diff --git a/pkg/executor/infoschema_reader_test.go b/pkg/executor/infoschema_reader_test.go index 56ec609a8e4e0..ff29f5b83c191 100644 --- a/pkg/executor/infoschema_reader_test.go +++ b/pkg/executor/infoschema_reader_test.go @@ -552,6 +552,15 @@ func TestTablesTable(t *testing.T) { testkit.Rows()) tk.MustQuery(fmt.Sprintf("select table_schema, table_name, tidb_table_id from information_schema.tables where table_schema = 'db1' and table_name = 't1' and tidb_table_id in (%s,%s)", tableMetas[0].id, tableMetas[1].id)).Check( testkit.Rows(toString(tableMetas[0]))) + + selectTables, err := strconv.Atoi(tk.MustQuery("select count(*) from information_schema.tables where upper(table_name) = 'T1'").Rows()[0][0].(string)) + require.NoError(t, err) + totalTables, err := strconv.Atoi(tk.MustQuery("select count(*) from information_schema.tables").Rows()[0][0].(string)) + require.NoError(t, err) + remainTables, err := strconv.Atoi(tk.MustQuery("select count(*) from information_schema.tables where upper(table_name) != 'T1'").Rows()[0][0].(string)) + require.NoError(t, err) + require.Equal(t, 2, selectTables) + require.Equal(t, totalTables, remainTables+selectTables) } func TestColumnTable(t *testing.T) { diff --git a/pkg/planner/core/memtable_infoschema_extractor.go b/pkg/planner/core/memtable_infoschema_extractor.go index 26079d2f553c6..5ea902ee9e5eb 100644 --- a/pkg/planner/core/memtable_infoschema_extractor.go +++ b/pkg/planner/core/memtable_infoschema_extractor.go @@ -260,8 +260,17 @@ func (e *InfoSchemaBaseExtractor) filter(colName string, val string) bool { return true } } + + toLower := false + if e.extractLowerString != nil { + toLower = e.extractLowerString[colName] + } + predVals, ok := e.ColPredicates[colName] if ok && len(predVals) > 0 { + if toLower { + return !predVals.Exist(strings.ToLower(val)) + } fn, ok := e.pushedDownFuncs[colName] if ok { return !predVals.Exist(fn(val)) diff --git a/pkg/planner/core/memtable_predicate_extractor.go b/pkg/planner/core/memtable_predicate_extractor.go index 77ef307c506e4..875add8daf950 100644 --- a/pkg/planner/core/memtable_predicate_extractor.go +++ b/pkg/planner/core/memtable_predicate_extractor.go @@ -51,6 +51,9 @@ import ( type extractHelper struct { enableScalarPushDown bool pushedDownFuncs map[string]func(string) string + + // Store whether the extracted strings for a specific column are converted to lower case + extractLowerString map[string]bool } func (extractHelper) extractColInConsExpr(ctx base.PlanContext, extractCols map[int64]*types.FieldName, expr *expression.ScalarFunction) (string, []types.Datum) { @@ -342,6 +345,11 @@ func (helper *extractHelper) extractCol( break } } + + if helper.extractLowerString == nil { + helper.extractLowerString = make(map[string]bool) + } + helper.extractLowerString[extractColName] = valueToLower return }