Fix incorrect or missed pruning when startsWith, LIKE, NOT LIKE used with FixedString column#99001
Merged
nihalzp merged 5 commits intoClickHouse:masterfrom Mar 9, 2026
Conversation
Contributor
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 97.83% (45/46) |
zlareb1
added a commit
to zlareb1/ClickHouse
that referenced
this pull request
Mar 17, 2026
…(PR ClickHouse#99001) PR ClickHouse#99001 fixed incorrect or missed pruning for startsWith, LIKE, NOT LIKE used with FixedString columns (KeyCondition.cpp:3101-3107). The fix keeps the original string constant when the key type (after stripping LowCardinality at line 3070) is String or FixedString. The existing test (04032_fixedstring_prefix_key_condition) covers plain FixedString and String keys but not LowCardinality(FixedString), which is a reachable path through the same fix. This adds LowCardinality(FixedString(40)) key variants for startsWith, LIKE, NOT LIKE, match, and their CAST forms. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 task
zlareb1
added a commit
to zlareb1/ClickHouse
that referenced
this pull request
Mar 17, 2026
…(PR ClickHouse#99001) The fix keeps the original string constant when the key type after LowCardinality stripping is FixedString or LowCardinality(FixedString). The existing test covers plain FixedString and String keys but not LowCardinality(FixedString), which is a reachable code path through the same fix. Extends 04032 with a LowCardinality(FixedString(40)) key table and exercises startsWith, LIKE, NOT LIKE, and match — with direct column, CAST(..., 'String'), and CAST(..., 'LowCardinality(String)') forms — all with force_primary_key = 1 to assert pruning is used and row-read counts are tight. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Given,
Wrong answer:
Addtionally,
FixedStringtoStringcast function monotonicity added. As a result, we prune for cases like these:Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix incorrect or less pruning when
startsWith,LIKE,NOT LIKEused withFixedStringcolumn. Additionally,FixedStringtoStringcast function can now prune granules when wrapped around key column. Closes #98940.Documentation entry for user-facing changes
Note
Medium Risk
Changes predicate-to-range conversion in
KeyConditionand function monotonicity metadata, which can affect query correctness and index pruning behavior for MergeTree scans.Overview
Fixes incorrect/overly-narrow primary-key range construction when
startsWith,LIKE/NOT LIKE, ormatchare applied toFixedStringkey columns by preserving string literals instead of converting them to paddedFixedString(N)during key-condition analysis.Marks
toString(FixedString)(includingLowCardinality(FixedString)) as always strict monotonic, allowing MergeTree pruning when casts wrap the key column. Adds unit tests for the new monotonicity and stateless query tests covering the FixedString prefix/pattern pruning regressions.Written by Cursor Bugbot for commit 30ae7ae. This will update automatically on new commits. Configure here.