Repository navigation
Keep the NULL partition in Delta Lake partition pruning when the filter's set holds NULL - #130192
Conversation
…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]>
Condense the key-choice comment in canBePruned to one line. 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) plus my own review (2 nits, none blocking).
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261108-165500 |
|
cc @kssenii @SmitaRKulkarni, could you review this and add the |
|
Workflow [PR], commit [1c4486b] Summary: ✅
AI ReviewSummaryPR #130192 fixes Delta Lake partition pruning discarding matching Missing context / blind spots
Final Verdict✅ Approve. No code changes requested. Independent runtime CI validation remains pending. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 22 s compile time in total, 8 of them have a recent master baseline. |
0ff7247
… can run 26.3's KeyDescription::getKeyFromAST takes no `virtuals` argument (#102827 is not on 26.3), so drop the `{}` the cherry-pick carried. The test built its Delta tables with INSERT INTO FUNCTION deltaLakeLocal under allow_delta_lake_writes. On 26.3 that setting is still called allow_experimental_delta_lake_writes, and a partitioned INSERT of a NULL value fails with NOT_IMPLEMENTED (#111793 is not on 26.3). Write the same tables by hand instead, as 26.3's 05237 test does: Parquet data files through file() and one add action per file, a NULL partition value committed as a JSON null under __HIVE_DEFAULT_PARTITION__. Two cases fail on 26.3 with and without this change, so they are dropped: `ifNull(p, 0) IN (0)` prunes the NULL partition (a MergeTree table partitioned by the same Nullable column returns the same wrong rows on 26.3), and `has([NULL, 'a'], s)` throws CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN (#115647 is not on 26.3). On 26.3 the fix keeps the NULL partition's file for `has([5, 7], p)`, so that case prunes 1 file instead of 2 (rows unchanged): 26.3 builds no set index for a UInt8 array over a Nullable(Int64) key; 26.3's MergeTree partition pruning does not use that predicate on a Nullable key either. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #130192 to 26.8: Keep the `NULL` partition in Delta Lake partition pruning when the filter's set holds `NULL`
Backport #130192 to 26.10: Keep the `NULL` partition in Delta Lake partition pruning when the filter's set holds `NULL`
Backport #130192 to 26.9: Keep the `NULL` partition in Delta Lake partition pruning when the filter's set holds `NULL`
…tition pruning when the filter's set holds `NULL`
…tition pruning when the filter's set holds `NULL`
…rtition pruning when the filter's set holds `NULL`
The `26.3` branch history was rewritten, so the previously merged `26.3` commits are no longer its ancestors. Conflicts in `src/Core/Field.cpp` and `src/Interpreters/InterpreterCreateQuery.cpp` (files this PR does not touch) are resolved by taking the `26.3` version; the result differs from `26.3` only in this backport's four files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t-130192 Backport #130192 to 26.3: Keep the `NULL` partition in Delta Lake partition pruning when the filter's set holds `NULL`
Related: #130177
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed Delta Lake partition pruning skipping the data files of a
NULLpartition when the filter's set holdsNULL, such ashas([NULL, 1], p)orp IN (NULL, 1)withtransform_null_in = 1.Description
On 26.10.2.103,
SELECT arraySort(groupArray(v)) FROM deltaLakeLocal('<dir>/t') WHERE has([NULL, 1], p)over a Spark-written Delta table partitioned by a nullablepwith aNULLpartition (p=__HIVE_DEFAULT_PARTITION__) returns[]instead of[2]. 26.3.60.2, 26.8.34.13 and 26.9.25.15 are the same.DeltaLake::PartitionPrunerbuilds its key over the non-Nullablecolumn types, soKeyConditiondrops theNULLelement of the set, whilecanBePrunedevaluates aNULLpartition value as+inf. Nothing in the set matches it, and the file is skipped.The pruner now evaluates a partition tuple that holds
NULLagainst the same key built over the table schema's own types (Nullablefor a nullable field). Tuples withoutNULLkeep the existing condition, so pruning of every other file is unchanged: aNullablekey for all files would stop pruninghas([NULL, 5], p)on tables without aNULLpartition, which the test checks. One narrow loss remains: in a multi-column table, a file whose tuple holdsNULLis no longer pruned by an untypedNULL-holding integer set on another nullable column (rows stay correct; MergeTree with aNullablepartition key behaves the same).#130177 fixes the same defect in the Iceberg data-file pruner with the same design. The Paimon partition pruner strips
Nullablethe same way; it is not changed here.Validation: the new test
05576_delta_lake_partition_pruning_null_in_setfails on master and passes with the fix (50 randomized runs); the Delta Lake stateless tests and thetest_storage_deltapartition-pruning integration tests pass.Workflow [PR]
Sync PR [sync-upstream/pr/130192]
Version info
26.11.1.1715-master(included in26.11and later)