Repository navigation
Fix Parquet pruning dropping NULL rows that ifNull, coalesce or a transform_null_in set matches - #128575
Fix Parquet pruning dropping NULL rows that ifNull, coalesce or a transform_null_in set matches#128575groeneai wants to merge 7 commits into
ifNull, coalesce or a transform_null_in set matches#128575Conversation
…match
Parquet filter push-down stands a NULL in a row group or page min/max range
in as `-inf` (`Parquet::Reader::adjustRangeFromIndexIfNeeded`), while the two
consumers that match a NULL against a key range assumed it is always `+inf`:
- `ifNull`, `coalesce` and `assumeNotNull` `getMonotonicityForRange` checked
only the right bound, so a range `[-inf (NULL), -1]` was reported monotonic
and `ifNull(id, 42) IN (42, 43)` pruned a row group whose NULL row gives 42.
- `MergeTreeSetIndex::checkInRange` compares a NULL set element (kept under
`transform_null_in`) only as equal to `+inf`, so the set `{NULL, 5}` never
intersected a range that holds its NULL at `-inf`.
The `+inf` assumption does not hold inside index analysis either: a
decreasing step (`Range::invert`) moves the `+inf` NULL of a MergeTree key to
`-inf`, so `ifNull(-id, 42) IN (42, 43)` on a Nullable key lost its NULL row
the same way.
Both consumers now treat an infinite bound on either side as a possible
NULL. The three functions are not monotonic when either bound is infinite,
and the set index widens a range with an included `-inf` up to `+inf` when the
set holds a NULL in that position (both `checkInRange` overloads). The
Parquet producer is unchanged, so ordinary predicates such as `id > 0` keep
pruning row groups that hold NULLs; the test checks that through
`ParquetPrunedRowGroups`.
Not changed here: Parquet bloom and dictionary filters hash a NULL set
element as the nested default, which is a separate mechanism.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in 05496 `gtest_monotonic.cpp` pinned the old right-only contract of `ifNull`, `coalesce` and `assumeNotNull` `getMonotonicityForRange`: a Nullable range with an infinite left bound was expected to be monotonic. It now passes both bounds and expects a range with an infinite bound on either side to be non-monotonic for Nullable and LowCardinality(Nullable) arguments. 05496 gains a Nullable MergeTree key under a decreasing step (`-id`), which moves the key's `+inf` NULL to `-inf` and is the only test line that needs the widening in the sparse `checkInRange` overload, and `ParquetPrunedRowGroups` checks over the all-NULL file, so a fix that stops pruning altogether for these shapes fails the test too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…edPages With the default 1 MiB data page size each column chunk was a single page, so the page arm only asserted counts: a page push-down that silently stopped pruning left every expected value unchanged. Both files are now written with `output_format_parquet_data_page_size = 1`, `output_format_parquet_batch_size = 1000` and no dictionary, giving 10 pages per 10000-row group, and the final section records `ParquetPrunedPages` next to `ParquetPrunedRowGroups` for an `id > 0` check and the all-NULL `ifNull` / `transform_null_in` queries of the page arm (20 / 10 / 10 pages pruned). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The two Nullable MergeTree key queries only asserted counts, so primary key analysis that stopped pruning (an unconditional set widening in the sparse `checkInRange` overload, or `ifNull` treated as never monotonic) left them unchanged. Both queries now carry a `log_comment`, and the final section checks `SelectedMarks < SelectedMarksTotal` for them in `system.query_log`: with the fix only the granule holding the NULL is read. This does not depend on the granule layout, which varies under randomized MergeTree settings (1 of 2 or 1 of 3 granules read over 50 randomized runs). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The MergeTree arm of the test exercises the sparse MergeTreeSetIndex::checkInRange overload, which primary key analysis takes only when use_lightweight_primary_key_index_analysis = 1. The runner randomizes that setting (False in ~40% of runs), and then the dense overload is used, which the Parquet arms already cover. Pin the setting to 1 with a per-setting random limit so the MergeTree arm always reaches the sparse overload. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reword the NULL-as-infinity line in the ifNull, coalesce and assumeNotNull monotonicity comments. 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; 5 rounds, 6 findings) plus my own review (5 rounds, 7 findings); 10 distinct below. The last round on
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261102-044100 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261102-023100 |
|
Workflow [PR], commit [5beca7f] Summary: ✅
AI ReviewSummaryThe PR prevents Parquet and Final VerdictStatus: ✅ Approve |
|
cc @nihalzp @al13n321, could you review this and add the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units406 translation units recompiled, 5493 s compile time in total, 406 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…s set holds NULL
The data-file partition key is built from removeNullable(source type), and
ManifestFilesPruner evaluates a NULL partition value as the single point +inf.
For a non-Nullable key KeyCondition drops every NULL set element, so
has([NULL, 1], b) became {1}, nothing matched +inf, and the data file of the
NULL partition was skipped. Dropping the NULL element is exact only for a
partition tuple without NULL.
The pruner now also builds the same key over Nullable inputs, with its own
condition, and uses that pair only for a partition tuple holding NULL in a
Nullable key position (a void field has type Tuple() and never selects it).
Every other tuple keeps the existing key and condition.
A Nullable key for every file is not used: for an untyped set holding NULL,
such as [NULL, 5] (Array(Nullable(UInt8))), the has() atom is declined for a
Nullable(Int64) key (not safely castable, and canBeInsideNullable() is false
for a Nullable key), so files of tables without a NULL partition would no
longer be pruned. Accepting a Nullable key at that KeyCondition guard would
give the untyped set the typed shape that the Parquet row-group filter still
gets wrong (ClickHouse#128570, ClickHouse#128575), and is MergeTree-wide.
The manifest-list pruner (master only) is fixed separately by ClickHouse#130158.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er's set holds NULL
DeltaLake::PartitionPruner built its partition key over removeNullable(type),
and canBePruned evaluates a NULL partition value (__HIVE_DEFAULT_PARTITION__) as
the point +inf. For a non-Nullable key column KeyCondition drops every NULL
element of a set, so has([NULL, 1], p) or p IN (NULL, 1) with
transform_null_in = 1 became the set {1}, nothing matched +inf, and the data
file of the NULL partition was skipped: its rows were silently lost. Dropping
the NULL element is exact only for a partition tuple without NULL.
The pruner now also builds the same tuple key over the table schema's own
types (Nullable for a nullable Delta field) and evaluates a partition tuple
that holds NULL against it, where NULL is an ordinary value of the key's type.
Tuples without NULL keep the existing condition, so their pruning is
unchanged. A Nullable key for every file would be correct too, but KeyCondition
declines an untyped NULL-holding set such as [NULL, 5] (Array(Nullable(UInt8)))
for a Nullable key, so has([NULL, 5], p) would stop pruning anything on tables
without a NULL partition. Accepting such sets for Nullable keys in KeyCondition
would change MergeTree as well, and would hand untyped NULL sets to the Parquet
row-group filter that still mishandles them (ClickHouse#128570, ClickHouse#128575).
Remaining loss: in a multi-column table a NULL-holding tuple is evaluated with
every nullable column Nullable, so an untyped NULL-holding integer set on
another nullable column no longer prunes that file (rows stay correct;
MergeTree with a Nullable partition key behaves the same).
The Iceberg data-file pruner had the same defect and gets the same design in
ClickHouse#130177.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts in ifNull.cpp, coalesce.cpp and assumeNotNull.cpp: keep master's [[nodiscard]] on getMonotonicityForRange together with this PR's check of both bounds. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #128505
Related: #128570
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed Parquet row group and page index filtering skipping rows with
NULLwhen the filter mapsNULLto a matching value throughifNull,coalesceor a set holdingNULL, such asifNull(x, 42) IN (42, 43)orintDiv(x, 10) IN (NULL, 5)withtransform_null_in = 1. Primary key analysis of aNullableMergeTree key skipped such rows too when a decreasing function is applied first, such asifNull(-x, 42) IN (42, 43).Description
On 26.8.34.13 (also 26.3.60.2),
SELECT count() FROM file('t.parquet') WHERE ifNull(id, toInt64(42)) IN (42, 43)returns 0 instead of 1 for a row group holding a NULL and otherwise only-1; it returns 1 withinput_format_parquet_filter_push_down = 0, input_format_parquet_page_filter_push_down = 0.The Parquet reader represents a NULL in a row group or page range as
-inf(adjustRangeFromIndexIfNeeded). The two consumers that match a NULL against a key range assumed it is+inf:ifNull,coalesceandassumeNotNullgetMonotonicityForRangechecked only the right bound, andMergeTreeSetIndex::checkInRangecompares a NULL set element only as equal to+inf. A decreasing step such as-idmoves the+infNULL of aNullableMergeTree key to-inftoo.Both consumers now treat an infinite bound on either side as a possible NULL: the three functions are not monotonic when either bound is infinite, and the set index widens a range with an included
-infup to+infwhen the set holds a NULL in that position (bothcheckInRangeoverloads). The reader is unchanged, so ordinary predicates (id > 0) still prune row groups and pages that hold NULLs. Both changes only make index analysis more conservative.Not covered: the Parquet bloom and dictionary filters can still drop a plain
x IN (NULL, 5)withtransform_null_in = 1; that separate mechanism is fixed in #128570.Validation: the new test fails on master in 19 NULL-matching lines and passes with the fix, 50/50 randomized runs.
ParquetPrunedRowGroups,ParquetPrunedPagesandSelectedMarkschecks confirm that row groups, pages and granules are still pruned where no NULL can match.gtest_monotonic.cppnow covers both bounds.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128575]