[BugFix] fix information_schema.tables not escaping special characters in equality predicates (backport #71273)#71402
Merged
Conversation
gengjun-git
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why I'm doing:
When querying
information_schema.tableswith an equality predicate like:The value
a_awas passed directly toPatternMatcher.createMysqlPattern()as a LIKE pattern, where_is treated as a single-character wildcard. This caused the query to return unrelated tables likeaba,a1a, etc., instead of only the exact tablea_a.Similarly, table names containing backslashes (e.g.
a\_a) were not handled correctly — the backslash and underscore interacted with LIKE pattern escaping rules in unexpected ways.Fixes #67447
What I'm doing
Fix
information_schema.tablesqueries with equality predicates (=) ontable_nameortable_schemaincorrectly treating LIKE-special characters (_,%,\) as wildcards instead of literal characters.Changes
PatternMatcher.convertMysqlPattern: Rewrite the two-pass conversion to a single-pass approach that correctly escapes regex metacharacters (e.g.(,),+,[,]) in table/database names, and properly handles a trailing backslash as a literal character.PatternMatcher.escapeLikeValue: Add a new utility method that escapes a literal string so it can be safely used as a MySQL LIKE pattern for exact matching (prefixing\,%, and_with a backslash).TablesSystemTable.evaluate: CallescapeLikeValue()on the value extracted from=predicates before passing it to the Thrift request. This is the primary fix — theSchemaTableEvaluateRuleoptimizer rule short-circuits simple equality queries oninformation_schema.tablesand evaluates them directly in the FE without going throughPlanFragmentBuilder.visitPhysicalSchemaScan.PlanFragmentBuilder.visitPhysicalSchemaScan: Also callescapeLikeValue()for=predicates onTABLE_NAME/TABLE_SCHEMA/DATABASE_NAMEin the SchemaScan path, which is used whenSchemaTableEvaluateRuleis disabled or when the predicate is not a simple equality.InformationSchemaDataSource.generateTablesInfoResponse: Remove the fallback OR-logic inmatchPatternand usematcher.match()directly, preventing false-positive matches when the pattern matcher rejects a name but the raw string comparison accidentally matches.What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check:
This is an automatic backport of pull request #71273 done by [Mergify](https://mergify.com).