diff --git a/pkg/infoschema/cluster.go b/pkg/infoschema/cluster.go index 5e6929233cdc9..3a6a97857701c 100644 --- a/pkg/infoschema/cluster.go +++ b/pkg/infoschema/cluster.go @@ -25,6 +25,7 @@ import ( "github.com/pingcap/tidb/pkg/sessionctx" "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util" + "github.com/pingcap/tidb/pkg/util/intest" "github.com/pingcap/tidb/pkg/util/sem" ) @@ -77,11 +78,15 @@ var memTableToAllTiDBClusterTables = map[string]string{ TableTiDBPlanCache: ClusterTableTiDBPlanCache, } +var memTableToAllTiDBClusterTablesWithLowerCase = make(map[string]string) + // memTableToDDLOwnerClusterTables means add memory table to cluster table that will send cop request to DDL owner node. var memTableToDDLOwnerClusterTables = map[string]string{ TableTiFlashReplica: TableTiFlashReplica, } +var memTableToDDLOwnerClusterTablesWithLowerCase = make(map[string]string) + // ClusterTableCopDestination means the destination that cluster tables will send cop requests to. type ClusterTableCopDestination int @@ -103,6 +108,7 @@ func GetClusterTableCopDestination(tableName string) ClusterTableCopDestination func init() { var addrCol = columnInfo{name: util.ClusterTableInstanceColumnName, tp: mysql.TypeVarchar, size: 64} for memTableName, clusterMemTableName := range memTableToAllTiDBClusterTables { + memTableToAllTiDBClusterTablesWithLowerCase[strings.ToLower(memTableName)] = strings.ToLower(clusterMemTableName) memTableCols := tableNameToColumns[memTableName] if len(memTableCols) == 0 { continue @@ -112,23 +118,34 @@ func init() { cols = append(cols, memTableCols...) tableNameToColumns[clusterMemTableName] = cols } + for memTableName, clusterMemTableName := range memTableToDDLOwnerClusterTables { + memTableToDDLOwnerClusterTablesWithLowerCase[strings.ToLower(memTableName)] = strings.ToLower(clusterMemTableName) + } } // IsClusterTableByName used to check whether the table is a cluster memory table. // Export for PhysicalTableScan.ExplainID func IsClusterTableByName(dbName, tableName string) bool { - dbName = strings.ToUpper(dbName) + intest.AssertFunc(func() bool { + return dbName == strings.ToLower(dbName) + }) switch dbName { - case util.InformationSchemaName.O, util.PerformanceSchemaName.O: - tableName = strings.ToUpper(tableName) - for _, name := range memTableToAllTiDBClusterTables { - name = strings.ToUpper(name) + case util.InformationSchemaName.L, util.PerformanceSchemaName.L: + intest.AssertFunc(func() bool { + return tableName == strings.ToLower(tableName) + }) + for _, name := range memTableToAllTiDBClusterTablesWithLowerCase { + intest.AssertFunc(func() bool { + return name == strings.ToLower(name) + }) if name == tableName { return true } } - for _, name := range memTableToDDLOwnerClusterTables { - name = strings.ToUpper(name) + for _, name := range memTableToDDLOwnerClusterTablesWithLowerCase { + intest.AssertFunc(func() bool { + return name == strings.ToLower(name) + }) if name == tableName { return true } diff --git a/pkg/infoschema/tables.go b/pkg/infoschema/tables.go index dbf001e26aa3b..adef2c7d26c2d 100644 --- a/pkg/infoschema/tables.go +++ b/pkg/infoschema/tables.go @@ -2493,7 +2493,7 @@ func createInfoSchemaTable(_ autoid.Allocators, _ func() (pools.Resource, error) columns[i] = table.ToColumn(col) } tp := table.VirtualTable - if IsClusterTableByName(util.InformationSchemaName.O, meta.Name.O) { + if IsClusterTableByName(util.InformationSchemaName.L, meta.Name.L) { tp = table.ClusterTable } return &infoschemaTable{meta: meta, cols: columns, tp: tp}, nil diff --git a/pkg/planner/core/explain.go b/pkg/planner/core/explain.go index 9b4703691a8e8..624ed48255ae6 100644 --- a/pkg/planner/core/explain.go +++ b/pkg/planner/core/explain.go @@ -168,7 +168,7 @@ func (p *PhysicalTableScan) ExplainID() fmt.Stringer { // TP overrides the TP in order to match different range. func (p *PhysicalTableScan) TP() string { - if infoschema.IsClusterTableByName(p.DBName.O, p.Table.Name.O) { + if infoschema.IsClusterTableByName(p.DBName.L, p.Table.Name.L) { return plancodec.TypeMemTableScan } else if p.isChildOfIndexLookUp { return plancodec.TypeTableRowIDScan @@ -190,7 +190,7 @@ func (p *PhysicalTableScan) ExplainNormalizedInfo() string { // OperatorInfo implements dataAccesser interface. func (p *PhysicalTableScan) OperatorInfo(normalized bool) string { - if infoschema.IsClusterTableByName(p.DBName.O, p.Table.Name.O) { + if infoschema.IsClusterTableByName(p.DBName.L, p.Table.Name.L) { return "" }