Skip to content

LIKE constant folding panics on patterns with repeated % #19561

@TCeason

Description

@TCeason

Repro

SELECT 'ababac' LIKE 'abab%%%%%';

Actual

The query fails with an internal panic:

Code: 1104
assertion failed: segments_len > 1

Panic site:

  • src/query/expression/src/filter/like.rs:144

Expected

Databend should either:

  • normalize redundant % and return the correct boolean result, or
  • return a regular SQL error

It must not panic.

Why this looks like the root cause

TypeChecker::resolve_like() can route constant LIKE expressions into constant folding, which eventually evaluates LikePattern::simple_pattern(). That function contains:

debug_assert!(segments_len > 1);

at:

  • src/query/expression/src/filter/like.rs:144

Repeated % can collapse the pattern into too few segments, violating that assumption and triggering the panic.

Impact

  • panic.log shows this happened 7 times in one migration batch.
  • It blocks automatic conversion of DuckDB LIKE coverage and turns a deterministic SQL case into an internal error.

Suggested fix direction

  • Normalize repeated % before building LikePattern, or
  • make simple_pattern() handle segments_len <= 1 safely instead of asserting

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: something isn't workingagent-issueAgent-created issue marker

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions