Repository navigation
Use bloom_filter skip index for IN with transform_null_in=1 and NULL-free set - #111329
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-0:20260722-064300 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-0:20260722-064300 |
|
cc @al13n321 @CurtizJ — could you review this? With transform_null_in=1 the analyzer rewrites IN to nullIn, and the bloom_filter skip index condition never classified nullIn/globalNullIn as FUNCTION_IN, so the index was silently dropped and the query full-scanned. This maps them to FUNCTION_IN when the set has no NULL (Set::hasNull()), excluding Array columns where whole-array equality hashing is unsound. |
|
Workflow [PR], commit [79a7a40] Summary: ✅
AI ReviewSummaryThis PR teaches Missing context / blind spots
Final Verdict✅ No new findings on the current head. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 12/13 (92.31%) · Uncovered code |
|
Fixed the Fast test regression on Root cause. Fix (commit 6cabd5a). Restrict the Second commit (f3ebce6) adds a type-compatibility guard Verified both directions on debug builds: 01681 fails before / passes after; 04545 (including the new type-mismatch case) passes; the |
Internal second-model review (Gate B, delta) — 1 finding, adjudicated (click to expand)Scoped delta review of the CI-fix commits (base 65c5fe9), engine codex.
|
…free set With transform_null_in=1 the analyzer rewrites `x IN (...)` to `nullIn(x, ...)` (and `globalIn` to `globalNullIn`). The bloom_filter index condition built the predicate hashes for these forms but never assigned an RPN function, leaving the atom FUNCTION_UNKNOWN so the index was not used and the query did a full scan. When the IN-set has no NULL element, nullIn selects exactly the same rows as in, so the index can prune. Map nullIn/globalNullIn to FUNCTION_IN for a directly indexed column when the set is single-column, NULL-free (Set::hasNull()), and type-compatible with the index (Set::areTypesEqual, modulo Nullable/ LowCardinality). When the set contains a NULL, nullIn also matches NULL rows, so the atom is left FUNCTION_UNKNOWN (no pruning). Guards: - Array columns are excluded: whole-array equality hashing is not sound for granules that mix empty and non-empty arrays (a pre-existing limitation shared by the `in` path), so nullIn must not start pruning them. - Only single-column sets: Set::hasNull() reports NULL content only for single-column sets, and a multi-column set against a single index column must keep raising NUMBER_OF_COLUMNS_DOESNT_MATCH rather than being pruned away. - Type must match: with transform_null_in=1 the set casts the key strictly (not accurate_or_null), so a type-incompatible set (e.g. a String index against IN (SELECT toUInt8(1))) throws at execution; pruning would swallow that error. The JSONAllPaths and map-subcolumn IN fast paths still recognize only in/globalIn, so they continue to full-scan under transform_null_in=1 (out of scope for this issue; extending them needs per-path NULL-semantics checks). `x = 'abc'` was already handled: transform_null_in does not rewrite `equals`. Closes: ClickHouse#111311 Co-Authored-By: Claude Opus 4.8 <[email protected]>
e2b2e4d to
4050d17
Compare
|
Force-pushed a strengthened version (squashed to one commit). The |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 11/13 (84.62%) · Uncovered code |
CI finish ledger — 4050d17Every failure below is owned by a fixing PR or a full-effort fix task. None is caused by this PR (the change gates the bloom_filter skip index for direct-column IN under transform_null_in=1; it cannot cause the coverage-suite stateless flakies, an integration check-table failure, or a stress-build failure). The earlier
Session id: cron:our-pr-ci-monitor:20260723-010000 |
|
Please also double check for the text index. |
|
I checked. The text index has the same gap, and so do the two legacy text bloom filters. Measured on a debug build of master,
Result rows are identical in every case, so this is lost pruning only, not wrong results. Sites:
One soundness finding, since the text path is not structurally safe the way I first expected. I would prefer to do those in a follow-up PR rather than here: three separate condition classes, and the text one has its own tokenizer and pre/postprocessor semantics that need their own test matrix. Tell me if you would rather have it all in this PR and I will fold it in. |
|
The follow-up is open: #112785 It covers the three text-family conditions I measured above, plus Two things worth flagging, both in the description there. The extra function names alone would give wrong results, because at |
|
@groeneai Code changes are good. Please condense your comments to 1 line or so in |
Keep only the local invariant at each site; the reasoning behind the guards is in the parent commit message. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The type check in the nullIn mapping was documented as preventing a swallowed
conversion error. That reason is wrong: the CANNOT_PARSE_TEXT error fires whether
or not the index prunes, so the existing error-code assertion passes even with the
check removed and does not pin it.
The real reason is that the two casts involved are not inverse. Index analysis
hashes the set value cast to the index type (toUInt8(1) -> String '1'), while
execution casts each column value to the set type ('01' -> UInt8 1, which matches).
A granule holding '01' therefore stores hash('01') while the index searches for
hash('1'), so pruning it silently drops a matching row.
Add an arm whose values all parse cleanly, so nothing throws, and where '01' and
'+1' are lossy under the round trip. It asserts result parity against
use_skip_indexes = 0 and the exact row count. Removing the type check turns both
assertions red, which the previous error-code assertion did not do. Also correct
the misleading comment above the existing case.
Test only, no behavior change.
Co-Authored-By: Claude Fable 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
globalNullIn is classified separately from nullIn in traverseTreeIn, but every positive pruning assertion used a local IN, so dropping globalNullIn from the classifier left the whole test green while GLOBAL IN silently stopped pruning (11/250 granules read, then 250/250). Assert reduced granules and the exact row count for GLOBAL IN as well. Test only, no behavior change. Co-Authored-By: Claude Fable 5 <[email protected]>
The pruning assertions filtered EXPLAIN rows with
explain LIKE '%Granules: %/%' AND toUInt64(extract(...)) < toUInt64(extract(...))
which assumes the LIKE is evaluated before the conversions. With
enable_analyzer = 0 that ordering does not hold, so the conversions also run
on rows that carry no "Granules: N/M" text. There extract returns an empty
string and toUInt64('') throws ATTEMPT_TO_READ_AFTER_EOF, which failed the
test 3 out of 3 reruns in the old-analyzer job and aborted the file at its
first assertion, leaving the remaining arms unexercised in that
configuration.
Use toUInt64OrZero so the conversions are total. All nine assertions are
affected, not only the first, so all nine are changed.
The assertion is unchanged in strength: it still requires read < total
granules. Rows without a granule line compare 0 < 0, which is false, so they
do not contribute, and the negative arms produce no granule line at all and
still yield 0. Verified by re-running the file under enable_analyzer 1 and 0
and by three mutations of the classifier, each of which still reddens the
test: dropping the nullIn wiring, dropping the areTypesEqual guard, and
dropping globalNullIn.
|
@groeneai Refresh to master |
|
@shankar-iyer Refreshed: merged Master had touched |
CI finish ledger - 79a7a40Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Not caused by this PR. The aborting query is Session id: cron:our-pr-ci-monitor:20260824-140000 |
|
Let me try 1 rerun to get a green CI. |
773aa57
Backport #111329 to 26.8: Use bloom_filter skip index for IN with transform_null_in=1 and NULL-free set
Backport #111329 to 26.7: Use bloom_filter skip index for IN with transform_null_in=1 and NULL-free set
Backport #111329 to 26.6: Use bloom_filter skip index for IN with transform_null_in=1 and NULL-free set
Backport #111329 to 26.5: Use bloom_filter skip index for IN with transform_null_in=1 and NULL-free set
|
@groeneai @shankar-iyer — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
|
Confirmed, with two corrections. The bug is real and reproduces at default settings. On master The provenance reading is right, so it is pre-existing rather than introduced here. This PR's entire net change to that file is the The blanket Withholding only the CREATE TABLE t (x Array(UInt32), y UInt32,
INDEX idx_xy (x, y) TYPE bloom_filter GRANULARITY 1)
ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 2;
INSERT INTO t VALUES ([], 1), ([1], 2), ([2], 3), ([3], 4);
SELECT count() FROM t WHERE (x, y) IN (([], 1), ([2], 3)); -- 1, expected 2One index per column hides this, because the array index then never sees the sibling. The map subcolumn branch is unaffected structurally, not merely untriggered: an Fix: #116449. Leaving #116431 open for that PR to close on merge. |
…N with transform_null_in=1 and NULL-free set
…N with transform_null_in=1 and NULL-free set
…N with transform_null_in=1 and NULL-free set
…N with transform_null_in=1 and NULL-free set
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Use the
bloom_filterskip index forINpredicates on a directly indexed column whentransform_null_in = 1and theIN-set contains noNULLvalue. Previously the index was skipped for such queries, forcing a full scan.Description
Closes: #111311
With
transform_null_in = 1the analyzer rewritesx IN (...)tonullIn(x, ...)(andglobalIntoglobalNullIn). Thebloom_filterskip index condition built the predicate hashes for these but never assigned an RPN function, so the atom stayedFUNCTION_UNKNOWNand the index was unused, forcing a full scan.When the
IN-set has noNULL,nullInselects exactly the same rows asin, so the index can prune. The fix mapsnullIn/globalNullIntoFUNCTION_INwhen the set is single-column,NULL-free and type-compatible with the index, and the column is not anArray. With aNULLin the set,nullInalso matchesNULLrows, so the atom is leftFUNCTION_UNKNOWN(unchanged behavior).x = 'abc'already worked:transform_null_indoes not rewriteequals.Scope: scalar left-hand side on a directly indexed column, which is the scope of the issue. Tuple lhs,
JSONAllPathsand map subcolumns still recognize onlyin/globalInand continue to full-scan.Those are deliberately not extended, because the checks this fix relies on cannot be evaluated there: the recursive
tuple(...)branch matches each element against its own index and is called withprepared_set = nullptr, andSet::hasNull()returnsfalsewheneverdata_types.size() != 1, so reusing the single-column guard on a tuple set is vacuous rather than merely wider. Measured with that extension applied, a 180-query parity sweep againstuse_skip_indexes = 0returned fewer rows than the truth arm for 17 queries; the sweep is clean on this PR. A test arm pins the contract, so extending the tuple branch on the single-column guard fails the test.Verified with
EXPLAIN indexes = 1that the index prunes forString,Nullable,LowCardinalityandLowCardinality(Nullable)with aNULL-free set, and does not prune for a set containingNULL, anArraycolumn, a type-incompatible set or a tuple lhs. Results matchuse_skip_indexes = 0in each case.Workflow [PR]
Sync PR [sync-upstream/pr/111329]
Version info
26.9.1.65(included in26.9and later)26.8.1.2003,26.7.6.15,26.6.4.22,26.5.8.21