@@ -115,14 +115,6 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex
115
115
is := sctx .GetInfoSchema ().(infoschema.InfoSchema )
116
116
e .is = is
117
117
118
- var getAllSchemas = func () []model.CIStr {
119
- dbs := is .AllSchemaNames ()
120
- slices .SortFunc (dbs , func (a , b model.CIStr ) int {
121
- return strings .Compare (a .L , b .L )
122
- })
123
- return dbs
124
- }
125
-
126
118
var err error
127
119
switch e .table .Name .O {
128
120
case infoschema .TableSchemata :
@@ -176,8 +168,7 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex
176
168
case infoschema .TableTiDBServersInfo :
177
169
err = e .setDataForServersInfo (sctx )
178
170
case infoschema .TableTiFlashReplica :
179
- dbs := getAllSchemas ()
180
- err = e .dataForTableTiFlashReplica (ctx , sctx , dbs )
171
+ err = e .dataForTableTiFlashReplica (ctx , sctx )
181
172
case infoschema .TableTiKVStoreStatus :
182
173
err = e .dataForTiKVStoreStatus (ctx , sctx )
183
174
case infoschema .TableClientErrorsSummaryGlobal ,
@@ -415,34 +406,36 @@ func (e *memtableRetriever) setDataForStatistics(ctx context.Context, sctx sessi
415
406
return nil
416
407
}
417
408
418
- func (e * memtableRetriever ) setDataForStatisticsInTable (schema model.CIStr , table * model.TableInfo , extractor * plannercore.InfoSchemaStatisticsExtractor ) {
409
+ func (e * memtableRetriever ) setDataForStatisticsInTable (
410
+ schema model.CIStr ,
411
+ table * model.TableInfo ,
412
+ ex * plannercore.InfoSchemaStatisticsExtractor ,
413
+ ) {
419
414
var rows [][]types.Datum
420
- if table .PKIsHandle {
421
- if ! extractor .Filter ("index_name" , "primary" ) {
422
- for _ , col := range table .Columns {
423
- if mysql .HasPriKeyFlag (col .GetFlag ()) {
424
- record := types .MakeDatums (
425
- infoschema .CatalogVal , // TABLE_CATALOG
426
- schema .O , // TABLE_SCHEMA
427
- table .Name .O , // TABLE_NAME
428
- "0" , // NON_UNIQUE
429
- schema .O , // INDEX_SCHEMA
430
- "PRIMARY" , // INDEX_NAME
431
- 1 , // SEQ_IN_INDEX
432
- col .Name .O , // COLUMN_NAME
433
- "A" , // COLLATION
434
- 0 , // CARDINALITY
435
- nil , // SUB_PART
436
- nil , // PACKED
437
- "" , // NULLABLE
438
- "BTREE" , // INDEX_TYPE
439
- "" , // COMMENT
440
- "" , // INDEX_COMMENT
441
- "YES" , // IS_VISIBLE
442
- nil , // Expression
443
- )
444
- rows = append (rows , record )
445
- }
415
+ if table .PKIsHandle && ex .HasPrimaryKey () {
416
+ for _ , col := range table .Columns {
417
+ if mysql .HasPriKeyFlag (col .GetFlag ()) {
418
+ record := types .MakeDatums (
419
+ infoschema .CatalogVal , // TABLE_CATALOG
420
+ schema .O , // TABLE_SCHEMA
421
+ table .Name .O , // TABLE_NAME
422
+ "0" , // NON_UNIQUE
423
+ schema .O , // INDEX_SCHEMA
424
+ "PRIMARY" , // INDEX_NAME
425
+ 1 , // SEQ_IN_INDEX
426
+ col .Name .O , // COLUMN_NAME
427
+ "A" , // COLLATION
428
+ 0 , // CARDINALITY
429
+ nil , // SUB_PART
430
+ nil , // PACKED
431
+ "" , // NULLABLE
432
+ "BTREE" , // INDEX_TYPE
433
+ "" , // COMMENT
434
+ "" , // INDEX_COMMENT
435
+ "YES" , // IS_VISIBLE
436
+ nil , // Expression
437
+ )
438
+ rows = append (rows , record )
446
439
}
447
440
}
448
441
}
@@ -451,7 +444,7 @@ func (e *memtableRetriever) setDataForStatisticsInTable(schema model.CIStr, tabl
451
444
nameToCol [c .Name .L ] = c
452
445
}
453
446
for _ , index := range table .Indices {
454
- if extractor . Filter ( "index_name" , index .Name .L ) {
447
+ if ! ex . HasIndex ( index .Name .L ) {
455
448
continue
456
449
}
457
450
nonUnique := "1"
@@ -528,7 +521,7 @@ func (e *memtableRetriever) setDataFromReferConst(ctx context.Context, sctx sess
528
521
continue
529
522
}
530
523
for _ , fk := range table .ForeignKeys {
531
- if ok && ex .Filter ( "constraint_name" , fk .Name .L ) {
524
+ if ok && ! ex .HasConstraint ( fk .Name .L ) {
532
525
continue
533
526
}
534
527
updateRule , deleteRule := "NO ACTION" , "NO ACTION"
@@ -753,7 +746,7 @@ func (e *memtableRetriever) setDataFromCheckConstraints(ctx context.Context, sct
753
746
if constraint .State != model .StatePublic {
754
747
continue
755
748
}
756
- if ok && ex .Filter ( "constraint_name" , constraint .Name .L ) {
749
+ if ok && ! ex .HasConstraint ( constraint .Name .L ) {
757
750
continue
758
751
}
759
752
record := types .MakeDatums (
@@ -797,7 +790,7 @@ func (e *memtableRetriever) setDataFromTiDBCheckConstraints(ctx context.Context,
797
790
if constraint .State != model .StatePublic {
798
791
continue
799
792
}
800
- if ok && ex .Filter ( "constraint_name" , constraint .Name .L ) {
793
+ if ok && ! ex .HasConstraint ( constraint .Name .L ) {
801
794
continue
802
795
}
803
796
record := types .MakeDatums (
@@ -1152,7 +1145,7 @@ func (e *memtableRetriever) setDataFromPartitions(ctx context.Context, sctx sess
1152
1145
rows = append (rows , record )
1153
1146
} else {
1154
1147
for i , pi := range table .GetPartitionInfo ().Definitions {
1155
- if ex .Filter ( "partition_name" , pi .Name .L ) {
1148
+ if ! ex .HasPartition ( pi .Name .L ) {
1156
1149
continue
1157
1150
}
1158
1151
rowCount = cache .TableRowStatsCache .GetTableRows (pi .ID )
@@ -1676,7 +1669,7 @@ func (e *memtableRetriever) setDataFromKeyColumnUsage(ctx context.Context, sctx
1676
1669
if checker != nil && ! checker .RequestVerification (sctx .GetSessionVars ().ActiveRoles , schema .L , table .Name .L , "" , mysql .AllPrivMask ) {
1677
1670
continue
1678
1671
}
1679
- if ex .Filter ( "constraint_schema" , schema .O ) {
1672
+ if ! ex .HasConstraintSchema ( schema .L ) {
1680
1673
continue
1681
1674
}
1682
1675
rs := keyColumnUsageInTable (schema , table , ex )
@@ -1748,29 +1741,27 @@ func (e *memtableRetriever) setDataForMetricTables() {
1748
1741
e .rows = rows
1749
1742
}
1750
1743
1751
- func keyColumnUsageInTable (schema model.CIStr , table * model.TableInfo , extractor * plannercore.InfoSchemaKeyColumnUsageExtractor ) [][]types.Datum {
1744
+ func keyColumnUsageInTable (schema model.CIStr , table * model.TableInfo , ex * plannercore.InfoSchemaKeyColumnUsageExtractor ) [][]types.Datum {
1752
1745
var rows [][]types.Datum
1753
- if table .PKIsHandle {
1754
- if extractor == nil || ! extractor .Filter ("constraint_name" , lowerPrimaryKeyName ) {
1755
- for _ , col := range table .Columns {
1756
- if mysql .HasPriKeyFlag (col .GetFlag ()) {
1757
- record := types .MakeDatums (
1758
- infoschema .CatalogVal , // CONSTRAINT_CATALOG
1759
- schema .O , // CONSTRAINT_SCHEMA
1760
- infoschema .PrimaryConstraint , // CONSTRAINT_NAME
1761
- infoschema .CatalogVal , // TABLE_CATALOG
1762
- schema .O , // TABLE_SCHEMA
1763
- table .Name .O , // TABLE_NAME
1764
- col .Name .O , // COLUMN_NAME
1765
- 1 , // ORDINAL_POSITION
1766
- 1 , // POSITION_IN_UNIQUE_CONSTRAINT
1767
- nil , // REFERENCED_TABLE_SCHEMA
1768
- nil , // REFERENCED_TABLE_NAME
1769
- nil , // REFERENCED_COLUMN_NAME
1770
- )
1771
- rows = append (rows , record )
1772
- break
1773
- }
1746
+ if table .PKIsHandle && ex .HasPrimaryKey () {
1747
+ for _ , col := range table .Columns {
1748
+ if mysql .HasPriKeyFlag (col .GetFlag ()) {
1749
+ record := types .MakeDatums (
1750
+ infoschema .CatalogVal , // CONSTRAINT_CATALOG
1751
+ schema .O , // CONSTRAINT_SCHEMA
1752
+ infoschema .PrimaryConstraint , // CONSTRAINT_NAME
1753
+ infoschema .CatalogVal , // TABLE_CATALOG
1754
+ schema .O , // TABLE_SCHEMA
1755
+ table .Name .O , // TABLE_NAME
1756
+ col .Name .O , // COLUMN_NAME
1757
+ 1 , // ORDINAL_POSITION
1758
+ 1 , // POSITION_IN_UNIQUE_CONSTRAINT
1759
+ nil , // REFERENCED_TABLE_SCHEMA
1760
+ nil , // REFERENCED_TABLE_NAME
1761
+ nil , // REFERENCED_COLUMN_NAME
1762
+ )
1763
+ rows = append (rows , record )
1764
+ break
1774
1765
}
1775
1766
}
1776
1767
}
@@ -1792,7 +1783,7 @@ func keyColumnUsageInTable(schema model.CIStr, table *model.TableInfo, extractor
1792
1783
continue
1793
1784
}
1794
1785
1795
- if extractor != nil && extractor . Filter ( "constraint_name" , filterIdxName ) {
1786
+ if ! ex . HasConstraint ( filterIdxName ) {
1796
1787
continue
1797
1788
}
1798
1789
@@ -1819,7 +1810,7 @@ func keyColumnUsageInTable(schema model.CIStr, table *model.TableInfo, extractor
1819
1810
}
1820
1811
}
1821
1812
for _ , fk := range table .ForeignKeys {
1822
- if extractor != nil && extractor . Filter ( "constraint_name" , fk .Name .L ) {
1813
+ if ! ex . HasConstraint ( fk .Name .L ) {
1823
1814
continue
1824
1815
}
1825
1816
@@ -2077,15 +2068,15 @@ func (e *memtableRetriever) setDataFromTableConstraints(ctx context.Context, sct
2077
2068
rows := make ([][]types.Datum , 0 , len (tables ))
2078
2069
for i , tbl := range tables {
2079
2070
schema := schemas [i ]
2080
- if ex .Filter ( "constraint_schema" , schema .L ) {
2071
+ if ! ex .HasConstraintSchema ( schema .L ) {
2081
2072
continue
2082
2073
}
2083
2074
if checker != nil && ! checker .RequestVerification (sctx .GetSessionVars ().ActiveRoles , schema .L , tbl .Name .L , "" , mysql .AllPrivMask ) {
2084
2075
continue
2085
2076
}
2086
2077
2087
2078
if tbl .PKIsHandle {
2088
- if ! ex .Filter ( "constraint_name" , lowerPrimaryKeyName ) {
2079
+ if ex .HasPrimaryKey ( ) {
2089
2080
record := types .MakeDatums (
2090
2081
infoschema .CatalogVal , // CONSTRAINT_CATALOG
2091
2082
schema .O , // CONSTRAINT_SCHEMA
@@ -2113,7 +2104,7 @@ func (e *memtableRetriever) setDataFromTableConstraints(ctx context.Context, sct
2113
2104
// The index has no constriant.
2114
2105
continue
2115
2106
}
2116
- if ex .Filter ( "constraint_name" , filterName ) {
2107
+ if ! ex .HasConstraint ( filterName ) {
2117
2108
continue
2118
2109
}
2119
2110
record := types .MakeDatums (
@@ -2128,7 +2119,7 @@ func (e *memtableRetriever) setDataFromTableConstraints(ctx context.Context, sct
2128
2119
}
2129
2120
// TiDB includes foreign key information for compatibility but foreign keys are not yet enforced.
2130
2121
for _ , fk := range tbl .ForeignKeys {
2131
- if ex .Filter ( "constraint_name" , fk .Name .L ) {
2122
+ if ! ex .HasConstraint ( fk .Name .L ) {
2132
2123
continue
2133
2124
}
2134
2125
record := types .MakeDatums (
@@ -2571,7 +2562,7 @@ func (e *memtableRetriever) setDataFromSequences(ctx context.Context, sctx sessi
2571
2562
}
2572
2563
2573
2564
// dataForTableTiFlashReplica constructs data for table tiflash replica info.
2574
- func (e * memtableRetriever ) dataForTableTiFlashReplica (_ context.Context , sctx sessionctx.Context , _ []model. CIStr ) error {
2565
+ func (e * memtableRetriever ) dataForTableTiFlashReplica (_ context.Context , sctx sessionctx.Context ) error {
2575
2566
var (
2576
2567
checker = privilege .GetPrivilegeManager (sctx )
2577
2568
rows [][]types.Datum
@@ -3677,7 +3668,7 @@ func (e *memtableRetriever) setDataFromIndexUsage(ctx context.Context, sctx sess
3677
3668
dom := domain .GetDomain (sctx )
3678
3669
rows := make ([][]types.Datum , 0 , 100 )
3679
3670
checker := privilege .GetPrivilegeManager (sctx )
3680
- extractor , ok := e .extractor .(* plannercore.InfoSchemaIndexUsageExtractor )
3671
+ extractor , ok := e .extractor .(* plannercore.InfoSchemaTiDBIndexUsageExtractor )
3681
3672
if ! ok {
3682
3673
return errors .Errorf ("wrong extractor type: %T, expected InfoSchemaIndexUsageExtractor" , e .extractor )
3683
3674
}
0 commit comments