Repository navigation
Add monotonicity for assumeNotNull, coalesce, ifNull to allow granules pruning for primary key and skip indexes - #94754
Merged
Conversation
Contributor
|
Workflow [PR], commit [22d7d9a] Summary: ❌
|
yariks5s
approved these changes
Feb 2, 2026
Merged
via the queue into
ClickHouse:master
with commit Feb 3, 2026
46186d9
249 of 260 checks passed
|
Thank you so much, impressive turn around time! |
pull Bot
pushed a commit
to admariner/ClickHouse
that referenced
this pull request
Apr 24, 2026
Rewrite `<op>(coalesce(a, b), const)` and `<op>(ifNull(a, b), const)` (and the flipped-argument forms) into `(a <op> const) OR (isNull(a) AND b <op> const)` inside `cloneDAGWithInversionPushDown`, before index analysis. The existing `use_skip_indexes_for_disjunctions` machinery in `MergeTreeDataSelectExecutor::mergePartialResultsForDisjunctions` then combines per-column pruning across the OR. PK analysis also benefits when one input is a primary key column. The rewrite only triggers when both `coalesce`/`ifNull` arguments are non-constant - the single-constant case is already handled by the monotonic chain introduced in ClickHouse#94754. Scope is limited to `equals`, `less`, `greater`, `lessOrEquals`, `greaterOrEquals`; negated and IN forms fall through unchanged. Gated behind the new setting `allow_key_condition_coalesce_rewrite` (default `true`). Co-Authored-By: Claude Opus 4.7 <[email protected]>
pull Bot
pushed a commit
to admariner/ClickHouse
that referenced
this pull request
Apr 24, 2026
Follow-up to 57be91e: `tryRewriteCoalesceComparison` in `KeyCondition.cpp` was hard-gated to 2-argument `coalesce`/`ifNull`. Extend it to arbitrary N by rewriting `<op>(coalesce(a_1, ..., a_N), const)` into (a_1 <op> const) OR (isNull(a_1) AND a_2 <op> const) OR (isNull(a_1) AND isNull(a_2) AND a_3 <op> const) ... OR (isNull(a_1) AND ... AND isNull(a_{N-1}) AND a_N <op> const) so per-column PK and skip indexes on each `a_i` are consulted via the existing `use_skip_indexes_for_disjunctions` machinery in `MergeTreeDataSelectExecutor::mergePartialResultsForDisjunctions`. The final branch needs no trailing `isNull(a_N)` - if execution reaches it, `a_N` is the `coalesce` result regardless of nullability. N=2 produces the same DAG shape as before, so `04114_coalesce_two_column_index_pruning` still passes byte-for-byte. Added `04115_coalesce_n_column_index_pruning` covering N=3, N=4, flipped-argument form, partial-column-indexed pruning, each of the 5 ordered operators, and the `allow_key_condition_coalesce_rewrite=0` off-baseline. The bail-out on any constant argument is kept intentionally: the 2-arg single- constant case is still handled by the monotonic-chain path from ClickHouse#94754, and a constant in the middle of the list would truncate `coalesce` (short-circuit on the first non-NULL), which needs separate handling. Co-Authored-By: Claude Opus 4.7 <[email protected]>
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve
assumeNotNull,coalesce,ifNullto enable primary key and skip index pruning for range predicates when key columns are wrapped in these functions. Closes #94689.Documentation entry for user-facing changes
Version info
26.2.1.183