Repository navigation
Do not use Parquet bloom and dictionary filters for an IN set holding NULL - #128570
Conversation
… NULL
With `transform_null_in = 1`, `KeyCondition` keeps a NULL element of an
`IN` set for a Nullable key. `parquetTryHashColumn` stripped the Nullable
wrapper and hashed the NULL as the nested default (0 / ''), but Parquet
bloom filters and dictionary pages hold only non-null values, so a row
group whose only matching rows were NULL was skipped:
SELECT count() FROM file('d.parquet', Parquet) WHERE id IN (NULL, 5)
SETTINGS transform_null_in = 1 -- 0 instead of 1
Return nullopt for a Nullable column that holds a NULL, as
`parquetTryHashField` already does for a NULL constant. `hash_many` then
skips that set column: a single-column atom gets no hash-filter pruning
(min/max pruning is unchanged) and a tuple atom still prunes by its other
elements. The dictionary-value callers pass non-Nullable decoded columns,
so only the set-hashing caller changes.
The new test checks dictionary-only and bloom-only reads for Nullable
integer, string and tuple sets, plus a NULL-free set on a Nullable column
that must still be pruned.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`has(const_array, key)` maps to the same set atom as `IN`, and the set keeps a NULL element for a Nullable key with default settings, so `WHERE has([NULL, 'b'], s)` on a Parquet file was wrong on 26.3, 26.8 and 26.10 without `transform_null_in`. The previous commit fixes it; add a dictionary-only and bloom-only arm for it (fails without the fix). `nullIn` is not affected: without `transform_null_in` its set is built without the NULL element. Drop the obsolete `query_plan_optimize_prewhere` pin. 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; 0 findings in both rounds) plus my own cold review (5 findings over 2 rounds).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261102-030900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261102-025000 |
|
cc @al13n321 @vitlibar, could you review this and add the |
|
Workflow [PR], commit [d5a19cb] Summary: ✅
AI ReviewSummaryThe PR prevents Final VerdictStatus: ✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
…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]>
|
🕵️ LGTM — correct and minimal. Reproduced on current master: A couple of small things, none blocking:
|
|
Thanks for the review. Line numbers below are at d5a19cb; I checked the types with a gdb breakpoint on
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed Parquet bloom filter and dictionary filter push-down skipping row groups whose
NULLrows match anINset containingNULLundertransform_null_in = 1, orhaswith a constant array containingNULL.Description
Related: #112580 (the
input_format_null_as_defaultvariant of NULL rows vs these filters)Related: #128575 (the min/max half)
On 26.3, 26.8 and 26.10, an
INset containingNULLundertransform_null_in = 1, orhas([NULL, 'b'], s)on aNullable(String)columnswith default settings, drops the matchingNULLrows of a Parquet file:KeyConditionkeeps aNULLset element for aNullablekey, andparquetTryHashColumnstripped theNullablewrapper and hashed theNULLas the nested default (0/''). Bloom filters and dictionary pages hold only non-null values, so a row group whose only matches areNULLrows was skipped.parquetTryHashColumnnow returnsnulloptfor a column that holds aNULL, asparquetTryHashFieldalready does for aNULLconstant. Such an atom gets no hash-filter pruning (min/max pruning is unchanged); in a tupleINthe other elements still prune. Only the set-hashing caller passesNullablecolumns: the dictionary callers hash columns of the decoded type, which is neverNullable(a dictionary page holds no NULL).Validation: the new test fails on master and passes 50/50 randomized runs; it covers dictionary-only and bloom-only,
Nullable(Int64),Nullable(String)and tuple sets,haswith a constant array containingNULL(default settings), plus a set withoutNULLthat must still be pruned. ORC and the MergeTreebloom_filterindex are not affected. Row-group and page min/max pruning has a separateNULLdefect (id IN (NULL)alone), addressed by #128575.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128570]
Version info
26.11.1.1786-master(included in26.11and later)