-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 pattern match case-insensitive for some infoschema tables #56378
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,9 +198,15 @@ func (e *InfoSchemaBaseExtractor) Extract( | |
} | ||
var likePatterns []string | ||
remained, likePatterns = e.extractLikePatternCol(ctx, schema, names, remained, colName, true, false) | ||
if len(likePatterns) == 0 { | ||
continue | ||
} | ||
regexp := make([]collate.WildcardPattern, len(likePatterns)) | ||
for i, pattern := range likePatterns { | ||
regexp[i] = collate.GetCollatorByID(collate.CollationName2ID(mysql.UTF8MB4DefaultCollation)).Pattern() | ||
// Because @@lower_case_table_names is always 2 in TiDB, | ||
// schema object names comparison should be case insensitive. | ||
ciCollateID := collate.CollationName2ID(mysql.UTF8MB4GeneralCICollation) | ||
regexp[i] = collate.GetCollatorByID(ciCollateID).Pattern() | ||
regexp[i].Compile(pattern, byte('\\')) | ||
} | ||
e.LikePatterns[colName] = likePatterns | ||
|
@@ -249,6 +255,11 @@ func (e *InfoSchemaBaseExtractor) filter(colName string, val string) bool { | |
if e.SkipRequest { | ||
return true | ||
} | ||
for _, re := range e.colsRegexp[colName] { | ||
if !re.DoMatch(val) { | ||
return true | ||
} | ||
} | ||
predVals, ok := e.ColPredicates[colName] | ||
if ok && len(predVals) > 0 { | ||
fn, ok := e.pushedDownFuncs[colName] | ||
|
@@ -661,6 +672,13 @@ func findTableAndSchemaByName( | |
schemaSlice = append(schemaSlice, st.schema) | ||
tableSlice = append(tableSlice, st.table) | ||
} | ||
sort.Slice(schemaSlice, func(i, j int) bool { | ||
cmp := schemaSlice[i].L < schemaSlice[j].L | ||
if cmp { | ||
tableSlice[i], tableSlice[j] = tableSlice[j], tableSlice[i] | ||
} | ||
return cmp | ||
}) | ||
return schemaSlice, tableSlice, nil | ||
} | ||
|
||
|
@@ -721,6 +739,13 @@ func findSchemasForTables( | |
remains = append(remains, tbl) | ||
} | ||
} | ||
sort.Slice(schemaSlice, func(i, j int) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we create a new slice to store tables instead of directly modifing input slice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The input slice is not used by anyone else. Let me add some comments for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
cmp := schemaSlice[i].L < schemaSlice[j].L | ||
if cmp { | ||
remains[i], remains[j] = remains[j], remains[i] | ||
} | ||
return cmp | ||
}) | ||
return schemaSlice, remains, nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need to sort by schema name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
291d8cc