Repository navigation
Make the primary key exclusion search cheap when the filter has non-key conditions - #123535
Conversation
…ey conditions `KeyCondition::checkInHyperrectangle` evaluates an atom it cannot analyze (`FUNCTION_UNKNOWN`, e.g. a condition on a column that is not part of the key) as `(true, true)` on every range. `and(range, unknown)` is then never certainly true, so the generic exclusion search split every range that may match down to single marks, although such an atom cannot exclude any of them. `KeyCondition::createWithUnknownAtomsAssumedTrue` returns a copy where every unknown atom is replaced with `ALWAYS_TRUE`, or with `ALWAYS_FALSE` under an odd number of `NOT`s. The copy has the same `can_be_true` on every range, so it excludes the same ranges, and it is certainly true on a range where no subrange can be excluded, so the search stops splitting there. Its `can_be_false` is not exact, so `markRangesFromPKRange` uses it only for the generic exclusion search without exact ranges, and only if the condition has unknown atoms. On a part with 781k marks, a key range combined with a non-key condition takes 0.013 s instead of 0.38 s, the same as the key range alone, with the same selected marks. On 5000 small parts the primary key analysis takes 14.7 ms instead of 23.7 ms; a condition without unknown atoms is not affected. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [2200d0d] Summary: ✅
AI ReviewSummaryThis PR teaches Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 2200d0d.
Changed lines: Changed C/C++ lines covered: 67/71 (94.37%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units356 translation units recompiled, 3771 s compile time in total, 356 of them have a recent master baseline. |
`OPTIMIZE TABLE ... FINAL` re-merged a single part of 3750 granules, which took about 140 s with the thread fuzzer. Insert with a single thread to get a single part directly instead. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123535&sha=5767b1fc68603ff697b5864097e9d1ab06a3a295&name_0=PR&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29 ClickHouse#123535 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
4f656cf
…rand-overflow-117237 Conflicts in `KeyCondition.cpp` resolved in favor of `master`: #123535 and #117355 made `KeyCondition::applyMonotonicFunctionsChainToRange` treat any non-fatal exception at a range endpoint as "cannot analyze" and `applyFunction` cache a failure sentinel for every exception. That subsumes this PR's `DECIMAL_OVERFLOW`-only handling, so the PR's `applyMonotonicFunctionsChainToRangeImpl` split is dropped from `KeyCondition.cpp` and `KeyCondition.h`. Co-Authored-By: Claude Opus 5.5 <[email protected]>

An atom that
KeyConditioncannot evaluate (e.g. a condition on a non-key column) is(true, true)on every range. Sokey_range AND non_key_conditionis never certainly true, and the generic exclusion search splits every matching range down to single marks, one check per mark.For this search,
markRangesFromPKRangenow uses a copy of the condition where such atoms are replaced withtrue(falseunder an odd number ofNOTs). The copy has the samecan_be_true, so the same ranges are excluded, but the search stops where nothing more can be excluded. Itscan_be_falseis not exact, so it is not used when exact ranges are collected.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improved performance of primary index analysis in queries that filter both by the primary key and by other columns, for example,
WHERE timestamp BETWEEN ... AND level = 'error'wherelevelis not in the primary key.Workflow [PR]
Sync PR [sync-upstream/pr/123535]
Version info
26.10.1.1780-master(included in26.10and later)