Skip to content

fix(query): handle empty LIKE ESCAPE in planner#19595

Merged
KKould merged 7 commits intodatabendlabs:mainfrom
sundy-li:fix/issue-19562-like-empty-escape-panic
Apr 8, 2026
Merged

fix(query): handle empty LIKE ESCAPE in planner#19595
KKould merged 7 commits intodatabendlabs:mainfrom
sundy-li:fix/issue-19562-like-empty-escape-panic

Conversation

@sundy-li
Copy link
Copy Markdown
Member

@sundy-li sundy-li commented Mar 23, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  • Fixes LIKE ... ESCAPE '' panics in planner type checking #19562
  • Stop the planner LIKE fast path from unwrapping an empty ESCAPE string.
  • Preserve existing operator/builtin fallback behavior by routing empty or non-single-character ESCAPE literals through the builtin like / like_any path instead of planner rewrites.
  • Add planner and sqllogictest regressions for empty-escape bindings and backslash-containing fallback cases.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Validation:

  • cargo test -p databend-common-sql --test it planner -- --nocapture
  • cargo test -p databend-common-sql --test it test_like_escape_preserves_existing_binding_semantics -- --nocapture
  • cargo clippy -p databend-common-sql --test it -- -D warnings
  • cargo fmt --all --check

Logic test added for CI coverage:

  • tests/sqllogictests/suites/query/issues/issue_19562.test

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions Bot added the pr-bugfix this PR patches a bug in codebase label Mar 23, 2026
@sundy-li sundy-li added the agent-reviewable Ready for agent review label Mar 23, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 63f2779b9c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/sql/src/planner/semantic/type_check.rs Outdated
@sundy-li
Copy link
Copy Markdown
Member Author

Blocking issue in resolve_like(): this patch stops the panic for ESCAPE , but it also lets empty-escape patterns fall into the const/prefix fast paths even when those rewrites are not semantics-preserving.\n\nExample: SELECT ax LIKE a\\x ESCAPE . After this patch new_like_str is borrowed as a\\x, check_const() returns true, and the planner rewrites to equality against a\\x. The runtime LIKE matcher still treats backslash as escaping the next character, so that pattern behaves like ax and should return true, not false. The same issue applies to prefix rewrites like a\\x%.\n\nSo this changes the failure mode from a planner panic to silent wrong-answer plans for some empty-escape inputs. I think the safe options here are either to reject ESCAPE with a normal SQL error, or to bypass the const/prefix rewrites when the escape string is present but empty.

sundy-li

This comment was marked as outdated.

sundy-li

This comment was marked as outdated.

sundy-li

This comment was marked as outdated.

@sundy-li sundy-li added the agent-changed Changed by agent label Mar 24, 2026
@sundy-li sundy-li added agent-changed Changed by agent and removed agent-changed Changed by agent labels Mar 24, 2026
@sundy-li sundy-li added agent-approved Approved by agent and removed agent-changed Changed by agent agent-reviewable Ready for agent review labels Mar 25, 2026
@sundy-li sundy-li requested a review from KKould April 5, 2026 01:14
@KKould KKould added this pull request to the merge queue Apr 8, 2026
Merged via the queue into databendlabs:main with commit 249f47a Apr 8, 2026
91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved Approved by agent pr-bugfix this PR patches a bug in codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LIKE ... ESCAPE '' panics in planner type checking

2 participants