Repository navigation
Use bloom filter skip index for arrayJoin(col) IN (set) and arrayJoin(col) = const - #109536
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260706-155000 |
|
Workflow [PR], commit [ea22ef2] Summary: ✅
AI ReviewSummaryThis PR extends the bloom-filter skip index so Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 52/60 (86.67%) · Uncovered code |
|
Fixed in 887a2f0. Thanks for catching the I took the second option you suggested (restrict the rewrite by the set contents) rather than propagating
Verified against your case with a table of whole empty-array granules followed by unique-tag granules:
Regression added to Note for context: the LEFT ARRAY JOIN clause with a bare column does not currently route an |
CI finish ledger — 887a2f0Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260707-143000 |
A bloom filter skip index on an Array column was used for hasAny(col, set) but not for the semantically equivalent arrayJoin(col) IN (set) / GLOBAL IN, which fell back to a full scan. Recognize arrayJoin(indexed_array_column) IN (set) (and GLOBAL IN) in MergeTreeIndexConditionBloomFilter::traverseTreeIn and map it to the same granule test as hasAny(indexed_array_column, set_elements). arrayJoin only multiplies rows, so a granule can produce a matching row only if at least one array element in the granule is in the set, which is exactly what the bloom filter evaluates for hasAny. NOT IN is intentionally not handled: a granule containing a set element can still yield rows whose arrayJoined value is outside the set, so no granule can be skipped. The rewrite fires only for the inner arrayJoin() function inside WHERE, which has inner-array-join semantics: empty arrays produce no rows, so hasAny is exact even when the set contains the element type's default value (a granule of all-empty arrays yields no matching row; a granule that actually stores the default value as an element is kept and returned). A LEFT ARRAY JOIN clause, which expands empty arrays to a default-value row, keeps its predicate above the ARRAY JOIN pipeline step and is never pushed into the skip index condition (getConjunctionNodes rejects ARRAY_JOIN nodes from filter push-down), so it cannot reach this branch and results stay correct. The test covers both the default-value inner case (pruning still fires, correct result) and a LEFT ARRAY JOIN over empty arrays (identical result with the skip index on and off). Closes: ClickHouse#109516 Co-Authored-By: Claude Opus 4.8 <[email protected]>
887a2f0 to
d9af984
Compare
|
Update on d9af984: I reverted the default-value guard I had added in 887a2f0. After investigating I could not construct any query where this branch produces a wrong result for a Reachability analysis:
Verified against a table with a whole granule of empty arrays: The guard was also actively harmful: for the reachable inner form it stopped pruning whenever the set contained a default value, e.g. The test now covers both: a default-value inner case (pruning still fires and the result is correct) and a |
|
Fixing PR for the s3-storage exit-125 signature-A (docker daemon death at post-run chown/teardown, all tests OK): #109673 |
CI finish ledger — d9af984Every failure below has an owner. None is caused by this PR (the diff is bloom-filter-only:
Session id: cron:our-pr-ci-monitor:20260707-200000 |
arrayJoin(arr) = x implies has(arr, x): a granule can produce a row matching the equality only if some array element in the granule equals the constant, which is exactly what the bloom filter evaluates for has. Mapped in traverseTreeEquals via getArrayJoinArgument, mirroring the existing arrayJoin(col) IN (set) -> hasAny handling. notEquals is not derivable and is left as a full scan. Closes: ClickHouse#109844 Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pre-PR validation gate for the added Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260708-213900 |
…rayjoin-in-109516
CI finish ledger — 83a850f (superseded by master-merge 3f2c043)Every failure below has an owner; none is PR-caused (our diff is MergeTreeIndexBloomFilter.cpp / RPNBuilder + the 04365 test, none of the failing areas).
Session id: cron:our-pr-ci-monitor:20260709-033000 |
CI finish ledger — 3f2c043Every failure below has an owner (a fixing PR). None is PR-caused (this PR's diff is
Session id: cron:our-pr-ci-monitor:20260709-080000 |
CI finish ledger — 24cdd05Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260729-103000 |
|
Dear @rschu1ze, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
@yariks5s If that's in your area, would you like to check this PR? |
|
🕵 @groeneai please check
|
|
@groeneai also a things that can be shorter: MergeTreeIndexBloomFilter.cpp:558-569: shrink: four locals to express two predicates. isFloat/isInteger free overloads for const DataTypePtr & already exist (IDataType.h:469,493,499) — drop both WhichDataType locals and both_integers: MergeTreeIndexBloomFilter.cpp:714-736: shrink: four nesting levels, but the block is the last thing before return false; — invert to guards, kills 4 closing braces. MergeTreeIndexBloomFilter.cpp:722, :951: shrink: index_type is a one-use local. Inline into the typeid_cast. MergeTreeIndexBloomFilter.cpp:726: shrink: row_size used once. Inline column->size(). 04365_bloom_filter_arrayJoin_in.sql:188-191: shrink: = 100000 and = -5 both assert "out-of-range constant declines, count 0 either way". One case covers it. 04365_bloom_filter_arrayJoin_in.sql:80-81: delete: the optimize_empty_string_comparisons = 1 pair tests the empty(s) rewrite, which this PR doesn't touch. The = 0 pair at 82-83 is the one that exercises the new equals derivation. Considered and rejected:
|
Review round 2 on ClickHouse#109536 (@yariks5s). Three test assertions did not check what they claimed, and the domain gate is expressed more directly. The NOT IN and != safety assertions searched the whole EXPLAIN output for "Granules: 13/13". The PrimaryKey section always emits that line, so they succeeded whether or not idx_tags was selected and pruning. Measured on the PR head: the skip-index block is absent from both plans, yet the same oracle also returns 1 for a predicate that does prune 2/13. They now assert that "Name: idx_tags" is absent, matching the LEFT ARRAY JOIN case in the same file. The cross-integer arm of bloomFilterHashDomainMatches was covered by arrayJoin(u) = 5 over an Array(UInt8) column. ClickHouse infers 5 as UInt8 (EXPLAIN QUERY TREE: constant_value_type UInt8), so it only exercised the identical-type path. It now uses toUInt64(5) for both the equality and the IN form. The exact-type Enum8 case had a single row, so no granule could ever be pruned and the case passed even when the index was never selected. It now has a second, non-matching label and an EXPLAIN indexes = 1 assertion on 1/2. Both new oracles were validated by mutation: with the cross-integer arm dropped and Enum declined, the three new assertions redden while the ones they replace stay green. Also: express the gate with the isFloat/isInteger free overloads for DataTypePtr, invert the traverseTreeIn arrayJoin block to early returns, inline two single-use locals, drop the duplicate out-of-range constant case, drop the optimize_empty_string_comparisons = 1 result pair, and shorten the test comments to one or two lines.
|
All three reproduce. Fixed in ea22ef2, with the shortening list applied. 1. Confirmed: neither plan contains a skip-index block, and the only 2. Confirmed: 3. Confirmed: one row cannot prune. Second non-matching label added, with an 2 and 3 are validated by mutation, not by passing: with the cross-integer arm removed and Enum declined, the new assertions go 1 -> 0 while the ones they replace stay green. Shortening: all six adopted. On Validation: Build ID Separately, the second-model review flagged three declines as missed optimizations: |
Backport #109536 to 26.8: Use bloom filter skip index for arrayJoin(col) IN (set) and arrayJoin(col) = const
Backport #109536 to 26.6: Use bloom filter skip index for arrayJoin(col) IN (set) and arrayJoin(col) = const
Backport #109536 to 26.7: Use bloom filter skip index for arrayJoin(col) IN (set) and arrayJoin(col) = const
…rrayJoin(col) IN (set) and arrayJoin(col) = const
…rrayJoin(col) IN (set) and arrayJoin(col) = const
…rrayJoin(col) IN (set) and arrayJoin(col) = const
…(set) The bloom_filter index has used these forms since ClickHouse#109536, but the text index reads every granule for them. The test checks the granule counts for =, IN, GLOBAL IN and IN with transform_null_in = 1, the forms that must not use the index, and the rows. It fails on master: the index checks print 0.
Closes: #109516
Closes: #109844
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A
bloom_filterskip index on anArraycolumn is now used forarrayJoin(column) IN (set),arrayJoin(column) GLOBAL IN (set)andarrayJoin(column) = const, the same way it was already used forhasAny(column, set)andhas(column, const). Previously thesearrayJoin ...forms fell back to a full scan.Description
MergeTreeIndexConditionBloomFilteronly accepted the argument ofIN/=as an indexed column directly or one of a few wrappers (tuple, map subcolumns, JSON paths).arrayJoin(tags)matched none, so the atom becameFUNCTION_UNKNOWNand nothing was pruned, whilehasAny(tags, ...)/has(tags, ...)already pruned.This PR recognizes
arrayJoin(indexed_array_column)on the left side and maps:arrayJoin(arr) IN (set)(andGLOBAL IN) to the same granule test ashasAny(arr, set_elements)(traverseTreeIn);arrayJoin(arr) = constto the same granule test ashas(arr, const)(traverseTreeEquals).arrayJoinonly multiplies rows, so a granule matches only if one of its array elements belongs to the set / equals the constant, which is what the bloom filter evaluates forhasAny/has.NOT IN/!=are intentionally not handled: a granule containing a set element / the constant can still yield rows whose value is outside the set / differs.Both derivations hash the constant after converting it towards the indexed element type, and SQL comparison coerces more widely than that conversion does. Where the two disagree the index was probed with bytes the predicate never compares, or the conversion threw during index analysis. Both are now gated on a proven-matching hash domain: an identical element and constant type, or integer against integer. Everything else is declined, leaving a full scan and keeping a conversion error reachable at execution rather than turning it into pruned granules. Integer widening and a
LowCardinalitywrapper stay admitted, so the pruning this PR adds is unchanged.Verified with
EXPLAIN indexes = 1that thearrayJoin ...forms prune likehasAny/has, thatNOT IN/!=do not prune, and that results are identical with the skip index on and off for every declined domain and for theLEFT ARRAY JOINcase. Test:04365_bloom_filter_arrayJoin_in.Workflow [PR]
Sync PR [sync-upstream/pr/109536]
Version info
26.9.1.161(included in26.9and later)26.8.1.2015,26.7.6.18,26.6.4.27