Skip to content

Normalize boolean-wrapped range predicates#338

Merged
KKould merged 1 commit intomainfrom
fix/boolean-range-normalization
May 3, 2026
Merged

Normalize boolean-wrapped range predicates#338
KKould merged 1 commit intomainfrom
fix/boolean-range-normalization

Conversation

@KKould
Copy link
Copy Markdown
Member

@KKould KKould commented May 3, 2026

What problem does this PR solve?

Boolean-wrapped range predicates such as (c1 > 10) = false, (c1 > 10) != true, and NOT (c1 > 10) were not normalized into simple range comparisons before index range detaching.

The range detacher also treated some non-transparent expression wrappers as if they were safe to inspect directly, which could detach an unsafe subset range from predicates that were not conjunctions.

Issue link:

What is changed and how it works?

  • Normalize boolean-wrapped ordered range comparisons during filter simplification:
    • (c1 > 10) = false -> c1 <= 10
    • (c1 > 10) != true -> c1 <= 10
    • NOT (c1 > 10) -> c1 <= 10
  • Keep range detaching sound by only preserving a single-side detached range through AND.
  • Stop detaching through non-transparent expression wrappers; only semantic-transparent wrappers like alias/type cast are unwrapped directly.
  • Add unit and SLT coverage for simplification, range detaching, query results, and explain plans using index scans.

Code changes

  • Has Rust code change
  • Has CI related scripts change

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Note for reviewer

Main review surface:

  1. Boolean range predicate normalization in SimplifyFilter.
  2. RangeDetacher soundness around partial range preservation and wrapper traversal.
  3. where_by_index result/explain coverage for normalized predicates using pk_index => (-inf, 10].

Validation used for this branch:

  • cargo fmt --check
  • cargo test boolean_wrapped_range_comparison --lib
  • cargo test range_detacher --lib
  • cargo run -p sqllogictest-test -- --path 'tests/slt/where_by_index*.slt'

@KKould KKould merged commit a188d53 into main May 3, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant