Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: make query case-insensitive for infoschema tables #56989

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkg/executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,3 +1066,48 @@ func TestInfoschemaTablesSpecialOptimizationCovered(t *testing.T) {
require.Equal(t, testCase.expect, covered, testCase.sql)
}
}

func TestCaseInsensitiveInfoSchemaRead(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("create database Test1")
tk.MustExec("create table Test1.Table1(Col1 int)")

ops := []string{"=", "!=", ">", ">=", "<", "<="}

testCases := []struct {
colName string
filter string
expected []int
}{
{
colName: "table_name",
filter: `"Table1"`,
expected: []int{1, 822, 561, 562, 261, 262},
},
{
colName: "table_schema",
filter: `"Test1"`,
expected: []int{1, 822, 0, 1, 822, 823},
},
}

sqlTemplates := []string{
"select count(*) from information_schema.tables where %s(%s) %s %s",
`select count(*) from information_schema.tables where %s(%s) %s %s and table_type != ""`, // disable count(*) optimization
}
for _, tc := range testCases {
for i, op := range ops {
for _, st := range sqlTemplates {
for _, stringFunc := range []string{"lower", "upper", ""} {
res := tk.MustQuery(fmt.Sprintf(st, stringFunc, tc.colName, op, tc.filter))
s := res.Rows()[0][0].(string)
actual, err := strconv.Atoi(s)
require.NoError(t, err)
require.Equal(t, tc.expected[i], actual)
}
}
}
}
}
11 changes: 6 additions & 5 deletions pkg/planner/core/memtable_infoschema_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ func (e *InfoSchemaBaseExtractor) Extract(
e.LikePatterns[colName] = likePatterns
e.colsRegexp[colName] = regexp
}
return remained
rewrited := make([]expression.Expression, 0, len(remained))
for _, expr := range remained {
newExpr := e.convertToLowerInExpression(ctx, expr)
rewrited = append(rewrited, newExpr)
}
return rewrited
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rewrited := make([]expression.Expression, 0, len(remained))
for _, expr := range remained {
newExpr := e.convertToLowerInExpression(ctx, expr)
rewrited = append(rewrited, newExpr)
}
return rewrited
for i, expr := range remained {
remained[i] = e.convertToLowerInExpression(ctx, expr)
}
return

}

// ExplainInfo implements base.MemTablePredicateExtractor interface.
Expand Down Expand Up @@ -262,10 +267,6 @@ func (e *InfoSchemaBaseExtractor) filter(colName string, val string) bool {
}
predVals, ok := e.ColPredicates[colName]
if ok && len(predVals) > 0 {
fn, ok := e.pushedDownFuncs[colName]
if ok {
return !predVals.Exist(fn(val))
}
return !predVals.Exist(val)
}
// No need to filter records since no predicate for the column exists.
Expand Down
Loading