Repository navigation
Keep the set skip index pruning granules that contain NULL - #123778
shankar-iyer merged 2 commits into
Conversation
`in` and `equals` on a `Nullable` column return `Nullable(UInt8)`, so the set index evaluates `c IN (803)` to NULL on a stored NULL set element. ClickHouse#111604 wrapped every nullable bit-wrapped atom in `ifNull(mask, UNKNOWN_FIELD)` to stop a constant NULL atom from propagating NULL through `__bitBoolMaskAnd`/`Or` (ClickHouse#103103). That also turned the NULL of a NULL set element into "can be true", so every granule holding a NULL passed `IN`/`=` and nothing was pruned (26.6: 32/448 granules, 26.8 and master: 448/448 on the issue's data). Map a NULL atom mask to "can be false" only (0b10). The mask connectives are only and/or/not/indexHint, i.e. Kleene logic, where a value fixed with a NULL operand stays the same for any definite replacement of it; so a row that makes the condition TRUE also makes it TRUE with every NULL atom read as FALSE, and no granule holding a matching row can be pruned. For a plain atom this is exact (WHERE treats NULL as not passing); under an un-pushed NOT it stays conservative. The ClickHouse#103103 shapes stay fixed: `(x AND NULL) OR y` -> `(x AND false) OR y` = `y`. This also matches how KeyCondition already reads a NULL hint. Closes ClickHouse#123705 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 cold review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261003-224503 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20261003-215300 |
|
Workflow [PR], commit [e8ee647] Summary: ✅
AI ReviewSummaryThis PR changes Final Verdict✅ No findings. The change looks correct and the added stateless coverage exercises both bulk and non-bulk set-index pruning paths. LLVM Coverage ReportMeasured on commit e8ee647.
Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code |
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, 13 s compile time in total, 7 of them have a recent master baseline. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only how a set skip index on a Nullable column handles NULL values during granule pruning. In the index condition, a NULL result now means 'can be false only' instead of 'unknown'. The PR also adds a stateless test. Neither ClickBench nor TPC-H defines set skip indexes, so no benchmark query runs the changed code. The flagged ClickBench improvements on Q30 (-14.5%) and Q31 (-12.6%) show almost no CPU change, so they are downgraded to not sure. Q28 (mixed test signals) and Q33 (within master's normal range) need no action, and the Q33 suppression is consistent with the diff. clickbenchFlagged queries (3 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
CI finish ledger - 50be039Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 160 checks completed, Session id: cron:our-pr-ci-monitor:20261004-040438 |
…null-element-prune
|
Fixing PR for |
|
@groeneai Sorry, I won't find time to review. |
|
@groeneai I am a bit unclear here :
So let's say column is |
|
The set index does not look Take a granule whose set is
#103103 is still fixed. There the NULL atom was a constant inside an I checked it on that granule plus CREATE TABLE t (id UInt32, x Nullable(String), INDEX i x TYPE set(0) GRANULARITY 1)
ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 4, index_granularity_bytes = 0;
INSERT INTO t VALUES (0,'aaa'),(1,'xyz'),(2,NULL),(3,NULL),(4,'abc'),(5,'xyz'),(6,'xyz'),(7,'xyz'),(8,'aaa'),(9,'xyz'),(10,'aaa'),(11,'xyz');
EXPLAIN indexes = 1 SELECT count() FROM t WHERE x = 'abc'; |
Closes: #123705
Related: #111604
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
setskip index on aNullablecolumn again skips granules whose stored set containsNULLbut not the searched value forINand=conditions, restoring the pruning lost in 26.8. Closes #123705.Description
Since 26.8, a
setindex on aNullablecolumn keeps every granule whose set containsNULLforc IN (...)/c = ..., so it prunes far less (on a 3.67M-row copy of the issue's table: 448/448 granules on 26.8 and master vs 32/448 on 26.6). Results are unchanged, but every such granule is read.The cause is my #111604.
inandequalson aNullablecolumn returnNullable(UInt8), so the index atom evaluates toNULLon aNULLset element. #111604 mapped everyNULLatom mask to "can be true or false" (to keep #103103 fixed), which also makes a granule that merely containsNULLlook like a match.This PR maps a
NULLatom mask to "can be false" only. The mask is combined only byAND/OR/NOT/indexHint(three-valued logic), where aNULLatom can never be what makes the condition true, so no granule holding a matching row is pruned; underNOTit stays conservative. The #103103 shapes ((x AND NULL) OR y) still keep the granule.Validation, on that copy: skip index 448/448 -> 32/448; for the issue's
FINALquerySelectedMarks448 -> 35 andSelectedRows3670016 -> 360448, the same as 26.6, with identical results. The same restoration holds forNullableString,Float64,Date,DecimalandInt8columns. The new test fails on master and passes with the fix; every other stateless test usingTYPE setgives the same result on both binaries.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/123778]
Version info
26.10.1.1635-master(included in26.10and later)