Skip to content

Do not use Parquet bloom and dictionary filters for an IN set holding NULL - #128570

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:parquet-hash-filters-null-in-set
Nov 10, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:parquet-hash-filters-null-in-set

Conversation

@groeneai

@groeneai groeneai commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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 NULL rows match an IN set containing NULL under transform_null_in = 1, or has with a constant array containing NULL.

Description

Related: #112580 (the input_format_null_as_default variant of NULL rows vs these filters)
Related: #128575 (the min/max half)

On 26.3, 26.8 and 26.10, an IN set containing NULL under transform_null_in = 1, or has([NULL, 'b'], s) on a Nullable(String) column s with default settings, drops the matching NULL rows of a Parquet file:

INSERT INTO FUNCTION file('d.parquet', Parquet)
  SELECT if(number = 0, NULL, if(number % 2 = 0, -1, 10))::Nullable(Int64) AS id FROM numbers(100);
SELECT count() FROM file('d.parquet', Parquet) WHERE id IN (NULL, 5) SETTINGS transform_null_in = 1; -- 0, expected 1

KeyCondition keeps a NULL set element for a Nullable key, and parquetTryHashColumn stripped the Nullable wrapper and hashed the NULL as the nested default (0 / ''). Bloom filters and dictionary pages hold only non-null values, so a row group whose only matches are NULL rows was skipped.

parquetTryHashColumn now returns nullopt for a column that holds a NULL, as parquetTryHashField already does for a NULL constant. Such an atom gets no hash-filter pruning (min/max pruning is unchanged); in a tuple IN the other elements still prune. Only the set-hashing caller passes Nullable columns: the dictionary callers hash columns of the decoded type, which is never Nullable (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, has with a constant array containing NULL (default settings), plus a set without NULL that must still be pruned. ORC and the MergeTree bloom_filter index are not affected. Row-group and page min/max pruning has a separate NULL defect (id IN (NULL) alone), addressed by #128575.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/128570]

Version info

  • Merged into: 26.11.1.1786-master (included in 26.11 and later)

groeneai and others added 2 commits November 2, 2026 02:27
… 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]>
@groeneai

groeneai commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author
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).

# Sev Finding Verdict Evidence / action
1 ⚠️ has(const_array, key) and nullIn reach the same set hashing without transform_null_in AGREE, fixed measured: has([NULL, 'b'], s) wrong with default settings on 26.3/26.8/26.10, fixed; has arm added (fails without the fix); nullIn not affected (its set holds no NULL without transform_null_in)
2 💡 test pinned the obsolete query_plan_optimize_prewhere AGREE, fixed pin removed
3 💡 PR body claimed a PR for the min/max half that does not exist AGREE, fixed wording corrected
4 💡 the has arm uses [NULL, 5]::Array(Nullable(Int64)); the natural [NULL, 5] literal (Array(Nullable(UInt8))) gets no hash pruning at all noted, not blocking the cast arm fails without the fix; String hashing is covered by the s IN (NULL, 'b') arm
5 💡 Description used an undefined column s AGREE, fixed defined in the text

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-self-slot-58:20261102-030900

@groeneai

groeneai commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT count() FROM file('d.parquet', Parquet) WHERE id IN (NULL, 5) SETTINGS transform_null_in = 1 returns 0 instead of 1 on every run (default settings otherwise), as does WHERE has([NULL, 'b'], s) with default settings; the new test reproduces both with dictionary-only and bloom-only arms.
b Root cause explained? A NULL set element is kept for a Nullable key; parquetTryHashColumn stripped Nullable and hashed the NULL as the nested default (0 / ''). Bloom filters and dictionary pages hold only non-null values, so a row group whose only matches are NULL rows was skipped.
c Fix matches root cause? Yes. The hash function returns nullopt for a column holding a NULL, the same rule parquetTryHashField applies to a NULL constant; not a guard at the pruning site.
d Test intent preserved / new tests added? New test 05497_parquet_hash_filters_null_in_set. Three mutations redden it: no fix (8 lines), check dropped (8 lines), refusing every Nullable column (liveness arm reads 200 rows instead of 0).
e Both directions demonstrated? Yes: FAIL on a base build of the same master commit, OK with the fix; 50/50 randomized runs green.
f Fix is general across code paths? parquetTryHashColumn has one Nullable caller (set hashing); the dictionary-value callers pass non-Nullable decoded columns. ORC and the MergeTree bloom_filter index were measured correct.
g Fix generalizes across inputs (params/datatypes/wrappers)? Measured fixed for Nullable(Int64), Nullable(String), a LowCardinality(Nullable(String)) hint, tuple IN, subquery sets, OR and has with a constant array containing NULL; nullIn measured not affected; unchanged for transform_null_in = 0 and non-Nullable keys.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or default change; such atoms only lose hash-filter pruning (min/max pruning unchanged).
i Invariants and contracts preserved? Yes. parquetTryHashColumn now honours its "nullopt if a value can't be hashed" contract; the early return precedes the exact-capacity reserve.

Session id: cron:clickhouse-impl-self-slot-57:20261102-025000

@groeneai

groeneai commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @al13n321 @vitlibar, could you review this and add the can be tested label so CI runs? parquetTryHashColumn hashed a NULL set element (transform_null_in = 1, or has over a constant array holding NULL) as the nested default, so the Parquet bloom and dictionary filters skipped row groups whose only matches are NULL rows; it now returns nullopt for a column holding a NULL.

@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d5a19cb]

Summary: ✅


AI Review

Summary

The PR prevents Parquet bloom and dictionary filters from discarding row groups whose NULL rows match an IN set or a constant-array has predicate. Reviewed the current diff, callers, tuple pruning, column wrappers, and all prior discussion; no actionable findings. The regression test covers both filters, integer and string columns, tuple sets, and continued pruning for a set without NULL; targeted CI passed all 50 runs. Tests were not run locally.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). labels Nov 2, 2026
@clickhouse-gh clickhouse-gh Bot added the can be tested Allows running workflows for external contributors label Nov 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d5a19cbf7 with master 28cd3f355 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline.

Job report

opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 8, 2026
…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]>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 9, 2026
…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]>
@PedroTadim PedroTadim self-assigned this Nov 9, 2026
@PedroTadim

Copy link
Copy Markdown
Member

🕵️ LGTM — correct and minimal. Reproduced on current master: id IN (NULL, 5) with transform_null_in=1 returns 0 under both dictionary and bloom push-down (expected 1), and the fix bails to no-hash-pruning, which is correctness-safe (only ever disables pruning). Confirmed the data-dictionary hashers (Reader.cpp:2620/2637) pass Nullable-typed but null-free columns, so they stay inert — the s IN (NULL,'b') dictionary case (rows_read:100) shows that path still prunes.

A couple of small things, none blocking:

  1. "Only the set-hashing caller passes Nullable columns" is a touch imprecise — the dictionary hashers pass Nullable-typed columns too; they're safe only because a decoded Parquet dictionary never holds an actual null. Might be worth tightening the comment to state that invariant (an adversarial file with a null in a dictionary page would now just disable that column's dictionary filter — safe, but good to be explicit).
  2. A NULL hidden under LowCardinality(Nullable) or Const(Nullable) would slip past checkAndGetColumn<ColumnNullable>. Presumably set columns never arrive that way here — worth a one-line confirmation.
  3. Nice to see the separate min/max NULL defect (id IN (NULL) alone) called out; a tracking issue for it would help.

@groeneai

@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the review. Line numbers below are at d5a19cb; I checked the types with a gdb breakpoint on parquetTryHashColumn on a master debug build.

  1. The dictionary callers don't pass Nullable columns. They hash columns of decoded_type, which is never Nullable (Reader.h:173; SchemaConverter.cpp:517-527 strips LowCardinality and Nullable from the type hint), and a dictionary page holds no NULL. In gdb, the calls from hashDictionaryValues get ColumnString or ColumnVector<Int64>, also for a Nullable(Int64) column and a LowCardinality(Nullable(String)) hint. So the sentence holds; I added that reason to the description.
  2. Confirmed. tryPrepareSetColumnsForIndex casts every set column to the key type with LowCardinality removed (KeyCondition.cpp:3599, 3679, 3699), and Set stores materialized elements (Set.cpp:529). The set column was ColumnNullable in all of these cases: s IN (NULL, 'zz') under a LowCardinality(Nullable(String)) hint, has([NULL, 'b']::Array(LowCardinality(Nullable(String))), s), and a LowCardinality(Nullable(String)) subquery set. If a wrapped column ever got there, it would fall through to the per-value Field path, which returns nullopt on a NULL.
  3. The min/max half is my Fix Parquet pruning dropping NULL rows that ifNull, coalesce or a transform_null_in set matches #128575 (open). Its test covers id IN (NULL, 5) under transform_null_in = 1 on row groups and pages where only the NULL row matches, which is the id IN (NULL) case. I linked it in the description instead of opening an issue.

@PedroTadim
PedroTadim enabled auto-merge November 9, 2026 16:49
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 9, 2026
Merged via the queue into ClickHouse:master with commit 9800ab6 Nov 10, 2026
187 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants