Skip to content

Commit 7a4c20e

Browse files
authored
infoschema: avoid strings.toUpper in the IsClusterTableByName (#59608)
close #59606
1 parent d851b15 commit 7a4c20e

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

pkg/infoschema/cluster.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/pingcap/tidb/pkg/sessionctx"
2626
"github.com/pingcap/tidb/pkg/types"
2727
"github.com/pingcap/tidb/pkg/util"
28+
"github.com/pingcap/tidb/pkg/util/intest"
2829
"github.com/pingcap/tidb/pkg/util/sem"
2930
)
3031

@@ -77,11 +78,15 @@ var memTableToAllTiDBClusterTables = map[string]string{
7778
TableTiDBPlanCache: ClusterTableTiDBPlanCache,
7879
}
7980

81+
var memTableToAllTiDBClusterTablesWithLowerCase = make(map[string]string)
82+
8083
// memTableToDDLOwnerClusterTables means add memory table to cluster table that will send cop request to DDL owner node.
8184
var memTableToDDLOwnerClusterTables = map[string]string{
8285
TableTiFlashReplica: TableTiFlashReplica,
8386
}
8487

88+
var memTableToDDLOwnerClusterTablesWithLowerCase = make(map[string]string)
89+
8590
// ClusterTableCopDestination means the destination that cluster tables will send cop requests to.
8691
type ClusterTableCopDestination int
8792

@@ -103,6 +108,7 @@ func GetClusterTableCopDestination(tableName string) ClusterTableCopDestination
103108
func init() {
104109
var addrCol = columnInfo{name: util.ClusterTableInstanceColumnName, tp: mysql.TypeVarchar, size: 64}
105110
for memTableName, clusterMemTableName := range memTableToAllTiDBClusterTables {
111+
memTableToAllTiDBClusterTablesWithLowerCase[strings.ToLower(memTableName)] = strings.ToLower(clusterMemTableName)
106112
memTableCols := tableNameToColumns[memTableName]
107113
if len(memTableCols) == 0 {
108114
continue
@@ -112,23 +118,34 @@ func init() {
112118
cols = append(cols, memTableCols...)
113119
tableNameToColumns[clusterMemTableName] = cols
114120
}
121+
for memTableName, clusterMemTableName := range memTableToDDLOwnerClusterTables {
122+
memTableToDDLOwnerClusterTablesWithLowerCase[strings.ToLower(memTableName)] = strings.ToLower(clusterMemTableName)
123+
}
115124
}
116125

117126
// IsClusterTableByName used to check whether the table is a cluster memory table.
118127
// Export for PhysicalTableScan.ExplainID
119128
func IsClusterTableByName(dbName, tableName string) bool {
120-
dbName = strings.ToUpper(dbName)
129+
intest.AssertFunc(func() bool {
130+
return dbName == strings.ToLower(dbName)
131+
})
121132
switch dbName {
122-
case util.InformationSchemaName.O, util.PerformanceSchemaName.O:
123-
tableName = strings.ToUpper(tableName)
124-
for _, name := range memTableToAllTiDBClusterTables {
125-
name = strings.ToUpper(name)
133+
case util.InformationSchemaName.L, util.PerformanceSchemaName.L:
134+
intest.AssertFunc(func() bool {
135+
return tableName == strings.ToLower(tableName)
136+
})
137+
for _, name := range memTableToAllTiDBClusterTablesWithLowerCase {
138+
intest.AssertFunc(func() bool {
139+
return name == strings.ToLower(name)
140+
})
126141
if name == tableName {
127142
return true
128143
}
129144
}
130-
for _, name := range memTableToDDLOwnerClusterTables {
131-
name = strings.ToUpper(name)
145+
for _, name := range memTableToDDLOwnerClusterTablesWithLowerCase {
146+
intest.AssertFunc(func() bool {
147+
return name == strings.ToLower(name)
148+
})
132149
if name == tableName {
133150
return true
134151
}

pkg/infoschema/tables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2493,7 +2493,7 @@ func createInfoSchemaTable(_ autoid.Allocators, _ func() (pools.Resource, error)
24932493
columns[i] = table.ToColumn(col)
24942494
}
24952495
tp := table.VirtualTable
2496-
if IsClusterTableByName(util.InformationSchemaName.O, meta.Name.O) {
2496+
if IsClusterTableByName(util.InformationSchemaName.L, meta.Name.L) {
24972497
tp = table.ClusterTable
24982498
}
24992499
return &infoschemaTable{meta: meta, cols: columns, tp: tp}, nil

pkg/planner/core/explain.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (p *PhysicalTableScan) ExplainID() fmt.Stringer {
168168

169169
// TP overrides the TP in order to match different range.
170170
func (p *PhysicalTableScan) TP() string {
171-
if infoschema.IsClusterTableByName(p.DBName.O, p.Table.Name.O) {
171+
if infoschema.IsClusterTableByName(p.DBName.L, p.Table.Name.L) {
172172
return plancodec.TypeMemTableScan
173173
} else if p.isChildOfIndexLookUp {
174174
return plancodec.TypeTableRowIDScan
@@ -190,7 +190,7 @@ func (p *PhysicalTableScan) ExplainNormalizedInfo() string {
190190

191191
// OperatorInfo implements dataAccesser interface.
192192
func (p *PhysicalTableScan) OperatorInfo(normalized bool) string {
193-
if infoschema.IsClusterTableByName(p.DBName.O, p.Table.Name.O) {
193+
if infoschema.IsClusterTableByName(p.DBName.L, p.Table.Name.L) {
194194
return ""
195195
}
196196

0 commit comments

Comments
 (0)