Skip to content

fix(query): avoid planner panic for invalid LIKE ESCAPE literals#19597

Closed
sundy-li wants to merge 2 commits into
databendlabs:mainfrom
sundy-li:fix/issue-19562-like-empty-escape-panic-20260323
Closed

fix(query): avoid planner panic for invalid LIKE ESCAPE literals#19597
sundy-li wants to merge 2 commits into
databendlabs:mainfrom
sundy-li:fix/issue-19562-like-empty-escape-panic-20260323

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 #19562

  • validate LIKE/NOT LIKE/LIKE ANY ... ESCAPE literals during planner type checking so invalid escape strings return a semantic error instead of panicking
  • add planner regression coverage for empty and multi-character ESCAPE literals

Tests

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

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: 1c3a372e77

ℹ️ 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 on lines +5623 to +5625
let escape_char = Self::validate_like_escape(span, escape)?;
let new_like_str = if let Some(escape_char) = escape_char {
Cow::Owned(convert_escape_pattern(like_str, escape_char))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate ESCAPE in LIKE subquery comparisons too

This new check only runs through resolve_like/resolve_like_escape. Expr::LikeSubquery still goes through resolve_scalar_subquery (type_check.rs:1315-1327,1601-1613), which converts BinaryOperator::Like(escape) straight into SubqueryComparisonOp::Like without validating the literal, and the runtime LIKE path in comparison.rs:1263-1268 just uses the first character (or ignores an empty string). So queries such as SELECT 'a' LIKE ANY (SELECT 'a') ESCAPE 'ab' or ... ESCAPE '' are still accepted instead of raising the new semantic error, leaving this fix incomplete for subquery forms.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Validated LIKE ESCAPE in resolve_scalar_subquery before building SubqueryComparisonOp::Like, and added planner coverage for invalid LIKE ANY (SELECT ...) ESCAPE literals (`` and ab).

Copy link
Copy Markdown
Member Author

@sundy-li sundy-li left a comment

Choose a reason for hiding this comment

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

The new validate_like_escape helper only runs through resolve_like and resolve_like_escape. LIKE ... (subquery) ESCAPE ... still goes through resolve_scalar_subquery -> SubqueryComparisonOp::Like without validating the escape literal, so queries like SELECT a LIKE ANY (SELECT a) ESCAPE or ... ESCAPE ab are still accepted instead of returning the new semantic error. Please validate the escape before constructing the subquery comparison and add a regression for a subquery form.

@sundy-li sundy-li added agent-changed Changed by agent and removed agent-reviewable Ready for agent review labels Mar 24, 2026
@sundy-li sundy-li added agent-reviewable Ready for agent review and removed agent-changed Changed by agent labels Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🤖 CI Job Analysis

Workflow: 23499540917

📊 Summary

  • Total Jobs: 86
  • Failed Jobs: 1
  • Retryable: 0
  • Code Issues: 1

NO RETRY NEEDED

All failures appear to be code/test issues requiring manual fixes.

🔍 Job Details

  • linux / test_logs: Not retryable (Code/Test)

🤖 About

Automated analysis using job annotations to distinguish infrastructure issues (auto-retried) from code/test issues (manual fixes needed).

@sundy-li sundy-li added agent-approved Approved by agent and removed agent-reviewable Ready for agent review labels Mar 24, 2026
@sundy-li sundy-li closed this Mar 25, 2026
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

1 participant