fix(query): handle empty LIKE ESCAPE in planner#19595
fix(query): handle empty LIKE ESCAPE in planner#19595sundy-li wants to merge 4 commits intodatabendlabs:mainfrom
Conversation
There was a problem hiding this comment.
💡 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".
|
Blocking issue in |
|
This fixes the planner panic, but it still leaves |
|
Verified locally that this is still unsafe to merge. The planner no longer panics on , but it still takes the constant fast path for raw backslash patterns because \ only rejects \ and . Runtime LIKE with an empty escape still feeds the raw pattern into the matcher, and the matcher still treats backslash followed by , , or \ as an escape sequence.\n\nThat leaves a wrong-answer path for empty-escape inputs such as a raw double-backslash pattern: the planner treats it as an ordinary constant string, while execution interprets it as an escaped single backslash. Please either reject \ with a normal SQL error, or plumb a real no-escape mode through LIKE planning and execution and add a regression that covers backslashes. |
|
Verified locally that this is still unsafe to merge. The planner no longer panics on an empty ESCAPE string, but it still takes the constant fast path for raw backslash patterns because check_const only rejects percent and underscore. Runtime LIKE with an empty escape still feeds the raw pattern into the matcher, and the matcher still treats backslash followed by percent, underscore, or backslash as an escape sequence. That leaves a wrong-answer path for empty-escape inputs such as a raw double-backslash pattern: the planner treats it as an ordinary constant string, while execution interprets it as an escaped single backslash. Please either reject empty ESCAPE strings with a normal SQL error, or plumb a real no-escape mode through LIKE planning and execution and add a regression that covers backslashes. |
|
Blocking issue in |
|
Blocking issue remains: this patch removes the panic for , but it still lets explicit empty-escape patterns hit the LIKE fast paths even when those rewrites are not semantics-preserving. A concrete case is a raw double-backslash pattern: \ rewrites it to string equality on two backslashes, while the current LIKE matcher still interprets that pattern as an escaped single backslash. That changes the failure mode from panic to silent wrong-answer plans for some empty-escape inputs. Please either reject empty \ with a normal SQL error, or bypass the const/prefix rewrites (and ideally plumb an explicit empty-escape mode through the matcher) and add a regression that covers backslashes. |
|
Blocking issue remains: this patch removes the panic for |
sundy-li
left a comment
There was a problem hiding this comment.
Blocking issue: this still does not preserve ESCAPE '' semantics for backslash patterns.
|
Blocking issue: this patch removes the planner panic for |
|
Re-verified locally: this still is not safe to merge. The panic is gone for Concrete example: Please either reject empty |
|
Blocking issue: this removes the panic, but it still does not validate LIKE ESCAPE literals as single-character values. Empty and multi-character escapes should stay semantic errors until the runtime can represent them correctly. |
|
Blocking issue in |
sundy-li
left a comment
There was a problem hiding this comment.
Blocking: this still changes from a planner panic into incorrect execution semantics. The planner now binds empty-escape patterns as if no escape character were present, but the runtime path still hard-codes as an escape in and . For example, will now bind and evaluate as a literal-percent match, even though disabling the escape character should leave the backslash literal instead of escaping . This needs either a runtime fix for the empty-escape case or a semantic error for unsupported patterns.
sundy-li
left a comment
There was a problem hiding this comment.
Blocking: this still changes LIKE ... ESCAPE '' from a planner panic into incorrect execution semantics. The planner now binds empty-escape patterns as if no escape character were present, but the runtime path still hard-codes \\ as an escape in src/query/functions/src/scalars/comparison.rs and src/query/expression/src/filter/like.rs.
For example, SELECT '%' LIKE '\\%' ESCAPE '' will now bind and evaluate as a literal-percent match, even though disabling the escape character should leave the backslash literal instead of escaping %. This needs either a runtime fix for the empty-escape case or a semantic error for unsupported ESCAPE '' patterns.
|
Blocking issue: this still changes LIKE ... ESCAPE '' from a planner panic into incorrect execution semantics. The planner now binds empty-escape patterns as raw strings, but the runtime like matcher still treats '' as an escape unconditionally in src/query/functions/src/scalars/comparison.rs:1263 and src/query/expression/src/filter/like.rs:102. For example, SELECT '%' LIKE '\%' ESCAPE '' will now bind and still match as a literal-percent pattern, even though disabling the escape should keep the backslash literal. Please either fix the runtime no-escape path or reject unsupported ESCAPE '' patterns semantically. |
|
Blocking: this patch removes the planner panic, but it still changes
This needs one of two fixes before merge:
|
|
Blocking follow-up with the exact repro:
This patch stops the planner panic, but the query still routes into runtime LIKE matching that treats So Before merge, this needs either:
|
|
Blocking concern from review:
That changes behavior for queries that previously worked when they missed the literal fast path, for example: It also leaves the operator inconsistent with This should be fixed without changing those semantics, for example by treating an empty escape as |
|
Blocking issue: this patch fixes the panic, but it also turns previously accepted \ operator forms into semantic errors while the exposed 3-arg \ builtin still accepts an empty third argument as 'no escape'. Before this PR, non-fast-path cases reached \ and then the builtin, so queries such as \ could bind successfully. After this change they fail at bind time, which is a behavior regression and leaves the operator inconsistent with \ unless both paths are tightened together. |
|
Blocking issue: this patch fixes the panic, but it also turns previously accepted |
|
Blocking for review: this patch fixes the planner panic by rejecting That regresses previously bindable operator forms such as |
|
Blocking review note:
Before this is safe to merge, the SQL surface needs one consistent rule: either tighten the builtin/runtime path in the same change, or preserve the existing non-panic operator behavior instead of rejecting only the operator syntax. |
|
Blocking review result: |
🤖 CI Job Analysis (Retry 1)
📊 Summary
❌ NO RETRY NEEDEDAll failures appear to be code/test issues requiring manual fixes. 🔍 Job Details
🤖 AboutAutomated analysis using job annotations to distinguish infrastructure issues (auto-retried) from code/test issues (manual fixes needed). |
I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
LIKE ... ESCAPE ''panics in planner type checking #19562ESCAPEstring.ESCAPEliterals through the builtinlike/like_anypath instead of planner rewrites.Tests
Validation:
cargo test -p databend-common-sql --test it planner -- --nocapturecargo test -p databend-common-sql --test it test_like_escape_preserves_existing_binding_semantics -- --nocapturecargo clippy -p databend-common-sql --test it -- -D warningscargo fmt --all --checkLogic test added for CI coverage:
tests/sqllogictests/suites/query/issues/issue_19562.testType of change
This change is