Skip to content

[BugFix] fix information_schema.tables not escaping special characters in equality predicates (backport #71273)#71402

Merged
wanpengfei-git merged 1 commit into
branch-4.0from
mergify/bp/branch-4.0/pr-71273
Apr 8, 2026
Merged

[BugFix] fix information_schema.tables not escaping special characters in equality predicates (backport #71273)#71402
wanpengfei-git merged 1 commit into
branch-4.0from
mergify/bp/branch-4.0/pr-71273

Conversation

@mergify
Copy link
Copy Markdown
Contributor

@mergify mergify Bot commented Apr 8, 2026

Why I'm doing:

When querying information_schema.tables with an equality predicate like:

SELECT * FROM information_schema.tables
WHERE table_schema = 'my_db' AND table_name = 'a_a';

The value a_a was passed directly to PatternMatcher.createMysqlPattern() as a LIKE pattern, where _ is treated as a single-character wildcard. This caused the query to return unrelated tables like aba, a1a, etc., instead of only the exact table a_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.tables queries with equality predicates (=) on table_name or table_schema incorrectly treating LIKE-special characters (_, %, \) as wildcards instead of literal characters.

Changes

  1. 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.

  2. 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).

  3. TablesSystemTable.evaluate: Call escapeLikeValue() on the value extracted from = predicates before passing it to the Thrift request. This is the primary fix — the SchemaTableEvaluateRule optimizer rule short-circuits simple equality queries on information_schema.tables and evaluates them directly in the FE without going through PlanFragmentBuilder.visitPhysicalSchemaScan.

  4. PlanFragmentBuilder.visitPhysicalSchemaScan: Also call escapeLikeValue() for = predicates on TABLE_NAME/TABLE_SCHEMA/DATABASE_NAME in the SchemaScan path, which is used when SchemaTableEvaluateRule is disabled or when the predicate is not a simple equality.

  5. InformationSchemaDataSource.generateTablesInfoResponse: Remove the fallback OR-logic in matchPattern and use matcher.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:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
    • This pr needs auto generate documentation
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 4.1
    • 4.0
    • 3.5
    • 3.4

This is an automatic backport of pull request #71273 done by [Mergify](https://mergify.com).

…s in equality predicates (#71273)

Signed-off-by: dontknow9179 <clin56322@gmail.com>
(cherry picked from commit 1224bae)
@wanpengfei-git wanpengfei-git merged commit 99b8362 into branch-4.0 Apr 8, 2026
35 of 36 checks passed
@wanpengfei-git wanpengfei-git deleted the mergify/bp/branch-4.0/pr-71273 branch April 8, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants