Repository navigation
Conversation
…le key Index analysis stands a NULL key value in as `+inf`, and `applyMonotonicFunctionsChainToRange` leaves that bound untransformed, because every function it accepts maps NULL to NULL. For a decreasing step it then called `Range::invert`, which rewrites a left `+inf` as `-inf`: - a granule of only NULLs became the whole universe, so it "may match" `intDiv(a, -3) = -2`, and the exact-range binary search spanned granules that do not match (debug `Inconsistent KeyCondition behavior`, the AST fuzzer failure STID 5182-4365 on ClickHouse#118721); - a granule `[8, NULL]` became `[-inf, intDiv(8, -3)]` and lost its NULLs, so `intDiv(a, -3) IN (NULL) SETTINGS transform_null_in = 1` returned 0 instead of 5 on every build (26.8.2.7 included). For a decreasing step over a Nullable argument, a range of only NULL is now kept, and a range of values and NULL becomes the whole universe. `matchesExactContinuousRange` no longer claims an exact range for such a chain, since the whole-universe image of a `[x, NULL]` suffix would trip the same check; the generic exclusion search still collects exact ranges per granule. Non-Nullable keys and increasing functions are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings), plus 2 nits from my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261005-223700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261005-212800 |
|
Workflow [PR], commit [d1bf761] Summary: ✅
AI ReviewSummaryThis PR fixes incorrect pruning for decreasing monotonic wrappers over Findings
Final Verdict |
Build profile diff (arm_release)Commit See the job log for details. |
…e key A size-1 set holding NULL, e.g. `intDiv(a, 3) IN (NULL) SETTINGS transform_null_in = 1` or `a IN (NULL)`, matches the NULL granules of a Nullable key, while `mayReadNullKeyValue` keeps them from matching wholly. `matchesExactContinuousRange` still reported an exact continuous range, so the binary search spanned NULL granules and the debug check threw `Inconsistent KeyCondition behavior` (AST fuzzer, STID 5182-6d6b). Release builds drop the exact range and return the correct count. Such a set now falls back to the generic exclusion search, which still collects exact ranges per granule. Sets without a NULL element are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on-decreasing-nullable-key Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
|
||
| const auto monotonicity = func->getMonotonicityForRange(*arg_type, field, field); | ||
| /// A decreasing step maps a range holding NULL to more than one interval. | ||
| if (!monotonicity.is_positive && isNullableOrLowCardinalityNullable(arg_type)) |
There was a problem hiding this comment.
applyMonotonicFunctionsChainToRange, a decreasing wrapper over a Nullable key only becomes inexact on the trailing mixed [x, NULL] granule; MergeTreeDataSelectExecutor already knows how to strip an inexact first/last granule from exact_ranges before keeping the binary-search result (MergeTreeDataSelectExecutor.cpp:2767-2774).
Returning false here for every decreasing step on a nullable type means predicates such as intDiv(a, -3) = -2 now always fall back to generic exclusion search on every part, even though they are still one continuous mark interval with at most one inexact boundary granule. On large parts that is a noticeable regression from the O(log N) binary-search path.
Can we keep the new range transformation but avoid the blanket Nullable-type rejection here, or at least make it depend on an actually inexact interior range rather than on the column type alone?
Related: #118721
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed index analysis of a decreasing function of a
Nullablesorting key, such asintDiv(a, -3): granules withNULLrows that the condition matches, for exampleintDiv(a, -3) IN (NULL)withtransform_null_in = 1, were skipped and the query returned too few rows. Granules that hold onlyNULLvalues are now skipped for conditions that cannot matchNULL.Description
On 26.8.2.7 a condition that matches
NULLrows through a decreasing function of the key loses them:On debug builds
intDiv(a, -3) = -2over a part withNULLkeys throwsInconsistent KeyCondition behavior, the AST fuzzer failure on #118721 (STID 5182-4365): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118721&sha=abb18b7a9a575e3b68dcdb2bc9f1f99f8a0f4045&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29Root cause. Index analysis stands a
NULLkey in as+inf, andapplyMonotonicFunctionsChainToRangeleaves that bound untransformed. For a decreasing step it then calledRange::invert, which rewrites a left+infas-inf: a granule of onlyNULLs became the whole universe, so the exact-range binary search spanned granules that do not match, and a granule[8, NULL]became[-inf, intDiv(8, -3)]and lost itsNULLs.Fix. For a decreasing step over a
Nullableargument, a range of onlyNULLis kept, and a range of values andNULLbecomes the whole universe;matchesExactContinuousRangeno longer claims an exact range for such a chain. The same function serves the primary key,INsets, minmax skip indexes and statistics-based part pruning.Also fixed. A size-1 set holding
NULLover aNullablekey, e.g.a IN (NULL)orintDiv(a, 3) IN (NULL)withtransform_null_in = 1, matches theNULLgranules whilemayReadNullKeyValuekeeps them from matching wholly, so it no longer gets an exact range either. Debug builds threw the same error (AST fuzzer on this PR, STID 5182-6d6b: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124111&sha=8c4386b1f9a5ed22725157d4614f5f325ea97708&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29); release counts were correct.Validation. The new test aborts the unfixed debug build, six lines differ on 26.8.2.7, and each mutation of the fix reddens it.
Workflow [PR]
Sync PR [sync-upstream/pr/124111]