Repository navigation
Fix bloom_filter index skipping granules for a FixedString constant - #114089
Conversation
|
Workflow [PR], commit [87f2c4a] Summary: ✅
AI ReviewSummaryThis PR fixes Final Verdict✅ No new findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 68/73 (93.15%) · Uncovered code |
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. |
|
|
🕵 Both remaining CI failures are unrelated to this PR (which touches only
|
|
I measured the leak before proposing a fix, and the Block-split of Across 14 days of
The On what changed on 08-10: #113772 merged at 07:46:51Z and enables So the fix belongs in the plan-graph cycle, not in |
|
Measured this: the leak reproduces deterministically on an ASAN build of master (1934 blocks, 0 direct, 5/5 runs), and PR #113397 takes it to clean on 5/5 with the same exception still firing, so it closes the cycle the selector storages are retained by. Full measurement, and a correction to an earlier claim of mine, on the tracking issue: #113954 (comment) |
…ty`-stripped key type
`has(map, constant)` and `mapContainsKey(map, constant)` reach the same
`arrayIndex.h` machinery by different routes, and the routes disagree on
`LowCardinality` keys.
`mapContainsKey` (and its `mapContains` alias, and `mapContainsValue`) is a
`FunctionMapToArrayAdapter` over the keys/values subcolumn, which keeps the
`LowCardinality` wrapper, so `executeArrayLowCardinality` casts the constant
straight to the dictionary type and strips the padding of a `FixedString`.
`has` over a `Map` instead goes through `FunctionArrayIndex::executeMap`, which
rewrites the map to an array of its keys and calls `recursiveRemoveLowCardinality`
on both arguments before `executeArrayImpl`, so it compares the raw padded bytes
exactly like `has` over an `Array(String)`.
The map branch of the `bloom_filter` index condition read the coercion mode from
`map_type->getKeyType()` with the wrapper still present, so for `has` it took the
dictionary-cast path. On `Map(LowCardinality(String), UInt8)` with
`INDEX idx mapKeys(m) TYPE bloom_filter`, `has(m, toFixedString('K1', 3))` hashed
the stripped `K1` while the function matches the physical key `K1\0`, and the
matching granule was pruned - the same class of silently-too-few-rows bug this
pull request fixes for the array spellings.
Strip `LowCardinality` from the element type for `has`, so its coercion mode is
read from the type `executeMap` actually passes into `executeArrayImpl`. On
`Map(LowCardinality(FixedString(3)), UInt8)` this also makes the index usable
again for an over-wide constant: `has` casts both sides to the least supertype
and cannot throw, so the constant is hashable and the index prunes, where the
dictionary-cast mode had to decline it to keep `TOO_LARGE_STRING_SIZE` reachable
for `mapContainsKey`.
The new test `04847_bloom_filter_map_has_low_cardinality_key` compares the
indexed answer against an unindexed oracle for `has` over `LowCardinality(String)`
and `LowCardinality(FixedString(3))` map keys, pins the row selections where
`has` and `mapContainsKey` deliberately disagree, and asserts that pruning still
happens. Its first cell answers 0 without this commit.
Addresses #114089 (comment)
|
🕵 The only red job on the current head ( Related: #114368 |
The array-search functions coerce a string constant with CAST before comparing it to the elements: `hasAny`/`hasAll`, and `has`/`indexOf` over a `FixedString` element, cast both sides to the least supertype, and `has`/`indexOf` over a `LowCardinality` element cast the constant straight to the dictionary type. A CAST of `FixedString` to `String` strips the trailing zero padding, while the index converted the constant with `convertFieldToType`, which keeps it. The index therefore hashed a value the function never compares and pruned granules that match, and in four cases an oversized constant reached a column `insert` during index analysis and raised `TOO_LARGE_STRING_SIZE` for a query that succeeds without the index. Replicate the coercion at the `Field` level: strip the padding of a `FixedString` constant, re-pad it to the width of the element type, and decline the index when the constant has no stored representation, so a runtime `TOO_LARGE_STRING_SIZE` stays reachable instead of becoming a silent empty result. `has`/`indexOf` over a plain `String` element compare the constant's raw padded bytes and keep the old conversion, as does `has(<constant array>, <indexed scalar>)`, whose runtime compares `Field`s directly. This is a reimplementation of #112693 with the same semantics; the tests are taken unchanged from that pull request. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`mapContainsKey`/`mapContainsValue`/`mapContains`, and `has` over a `Map`, are adapters of the same arrayIndex.h machinery as `has` over an array, so a `bloom_filter` index on `mapKeys`/`mapValues` must coerce a string constant the same way. Addresses the review comment on the map path. The subcolumn the runtime compares against keeps the `LowCardinality` wrapper that the `mapKeys`/`mapValues` index expression strips, so the coercion mode is read from the `Map` type itself: with `Map(LowCardinality(String), ...)` keys the index header shows `Array(String)`, but the function casts the constant to the dictionary type and compares the stripped form, while a plain `String` key compares the raw padded bytes. That mismatch made even a matching granule prune silently on master; the new test covers `String`, `FixedString`, `LowCardinality(String)` and `LowCardinality(FixedString)` keys and values against an unindexed oracle, with pruning and `TOO_LARGE_STRING_SIZE` reachability assertions. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…a `bloom_filter` index The review asked whether `has`/`indexOf`/`hasAny`/`hasAll` over an indexed `mapKeys`/`mapValues` expression still mis-coerce a constant when the map keys or values are `LowCardinality`. They do not: `mapKeys`/`mapValues` return a full `Array` with `LowCardinality` stripped from the type, so the runtime compares exactly the way the stripped index-header type says - raw padded bytes over `String` elements, the least supertype over `FixedString` - and the dictionary-cast path is only reachable through the keys/values subcolumn behind `mapContainsKey`/`mapContainsValue`, which the `Map`-type branch already handles. Pin that with an oracle-comparison test.
…4846 to avoid collision with 04845_type_evolution_matrix_nested_multi from master
…ty`-stripped key type
`has(map, constant)` and `mapContainsKey(map, constant)` reach the same
`arrayIndex.h` machinery by different routes, and the routes disagree on
`LowCardinality` keys.
`mapContainsKey` (and its `mapContains` alias, and `mapContainsValue`) is a
`FunctionMapToArrayAdapter` over the keys/values subcolumn, which keeps the
`LowCardinality` wrapper, so `executeArrayLowCardinality` casts the constant
straight to the dictionary type and strips the padding of a `FixedString`.
`has` over a `Map` instead goes through `FunctionArrayIndex::executeMap`, which
rewrites the map to an array of its keys and calls `recursiveRemoveLowCardinality`
on both arguments before `executeArrayImpl`, so it compares the raw padded bytes
exactly like `has` over an `Array(String)`.
The map branch of the `bloom_filter` index condition read the coercion mode from
`map_type->getKeyType()` with the wrapper still present, so for `has` it took the
dictionary-cast path. On `Map(LowCardinality(String), UInt8)` with
`INDEX idx mapKeys(m) TYPE bloom_filter`, `has(m, toFixedString('K1', 3))` hashed
the stripped `K1` while the function matches the physical key `K1\0`, and the
matching granule was pruned - the same class of silently-too-few-rows bug this
pull request fixes for the array spellings.
Strip `LowCardinality` from the element type for `has`, so its coercion mode is
read from the type `executeMap` actually passes into `executeArrayImpl`. On
`Map(LowCardinality(FixedString(3)), UInt8)` this also makes the index usable
again for an over-wide constant: `has` casts both sides to the least supertype
and cannot throw, so the constant is hashable and the index prunes, where the
dictionary-cast mode had to decline it to keep `TOO_LARGE_STRING_SIZE` reachable
for `mapContainsKey`.
The new test `04847_bloom_filter_map_has_low_cardinality_key` compares the
indexed answer against an unindexed oracle for `has` over `LowCardinality(String)`
and `LowCardinality(FixedString(3))` map keys, pins the row selections where
`has` and `mapContainsKey` deliberately disagree, and asserts that pruning still
happens. Its first cell answers 0 without this commit.
Addresses #114089 (comment)
…it the flaky-check time budget The private-CI flaky check (`Stateless tests (amd_asan_ubsan, flaky check, s3 storage, meta in keeper)`) runs the test at 150-190 seconds per iteration and failed 3 of 193 runs with `Test runs too long (> 180s). Make it faster.` The test carried 24 tables and 127 SELECT cells, each paying the per-query overhead of that configuration. Move the pruning/plan half (the `p_*`, `q_str`, `*_sc` and `*fs3m` tables with the `EXPLAIN indexes` cells) into a new test 04872_bloom_filter_array_fixed_string_pruning, keeping the oracle-comparison half in place. The two halves were already independent: no table crosses the boundary, and the concatenated reference output is unchanged. Co-Authored-By: Claude Fable 5 <[email protected]>
d7566be to
052e739
Compare
|
🕵 Investigated the only non-green gate, |
alexey-milovidov
left a comment
There was a problem hiding this comment.
A mechanical fix, nothing elegant here. But the problem exists and has to be fixed. LGTM.
ReproducerCREATE TABLE k (id UInt64, v Array(String), INDEX idx v TYPE bloom_filter GRANULARITY 1)
ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 1;
INSERT INTO k VALUES (0,['V0']),(1,['V0\0']),(2,['X']);
SELECT count() FROM k WHERE hasAny(v, [toFixedString('V0',3)]); -- 0, wrong
SELECT count() FROM k WHERE hasAny(v, [toFixedString('V0',3)]) SETTINGS use_skip_indexes=0; -- 1Results:
CC component owner: @shankar-iyer @rschu1ze Analysis metadata
Introducing change: not identified
|
Related: #112693
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes
hasAny,hasAll,has,indexOf,mapContainsKey,mapContainsValueandmapContainsreturning too few rows, or failing withTOO_LARGE_STRING_SIZE, when abloom_filterindex is queried with aFixedStringconstant. The index hashed the padded form of the constant while the function compares the unpadded one, so a matching granule was skipped.Description
A
bloom_filterskip index silently returns too few rows when the constant is aFixedString, and in four cases raisesTOO_LARGE_STRING_SIZEon a query that succeeds without the index:Root cause: the array-search functions coerce the constant with CAST before comparing it to the elements (
hasAny/hasAll, andhas/indexOfover aFixedStringelement, cast both sides to the least supertype;has/indexOfover aLowCardinalityelement cast the constant straight to the dictionary type), and a CAST ofFixedStringtoStringstrips the trailing zero padding. The index instead converted the constant withconvertFieldToType, which keeps the padding, so it hashed a value the function never compares and pruned granules that match. The error cases are the same cause: an oversizedFieldpassed through unchanged and reached a columninsertduring index analysis.The fix replicates the coercion at the
Fieldlevel, which is exact because the string casts involved are fully predictable: strip the padding of aFixedStringconstant, re-pad it to the width of the element type (the stored form of every element the function can match), and decline the index when the constant has no stored representation, so a runtimeTOO_LARGE_STRING_SIZEstays reachable instead of becoming a silent empty result. The direct cast to a dictionary type rejects an over-wideFixedStringconstant before stripping, while the supertype cast strips first - that one ordering difference is the only divergence between the two coercions, so it is aboolrather than a second code path.has/indexOfover a plainStringelement compare the constant's raw padded bytes (executeString) and keep the old conversion, as doeshas(<constant array>, <indexed scalar>), whose runtime comparesFields directly.MappredicatesmapContainsKey,mapContainsValue,mapContainsandhasover aMapare adapters of the samearrayIndex.hmachinery, so abloom_filterindex onmapKeys/mapValuesneeds the same coercion - and it needs to pick the mode from theMaptype rather than from the index header, because themapKeys/mapValuesindex expression stripsLowCardinalityfrom the key/value type while themapContains*adapters run over the keys/values subcolumn, which keeps it. Reading the mode from the stripped header alone would still prune a matching granule onMap(LowCardinality(String), ...), which is broken onmastertoday independently of the constant's width.hasover aMapis the one exception, and it goes the other way:FunctionArrayIndex::executeMaprewrites the map to an array of its keys and callsrecursiveRemoveLowCardinalityon both arguments beforeexecuteArrayImpl, so it compares the raw padded bytes exactly likehasover anArray(String), unlikemapContainsKeyon the same column. Its element type is therefore stripped ofLowCardinalitybefore the mode is read.The direct array spellings
has(mapKeys(m), ...)/indexOf(mapValues(m), ...)need no special handling:mapKeys/mapValuesreturn a fullArraywithLowCardinalitystripped from the type, so the index header type is already the type the runtime compares against.This supersedes #112693 with a smaller implementation of the same semantics (one
Field-level helper instead of a two-mode column-cast round-trip throughgetLeastSupertypeplus a batched clone ofcreateColumnFromConstantArray). The array test - 115 assertions over the full element-type/function/constant-width matrix, including granule-pruning andTOO_LARGE_STRING_SIZEreachability assertions - is taken unchanged from that pull request and passes byte-identically, so the two implementations are behaviorally equivalent on the covered surface. Three further tests cover theMappredicates, the directmapKeys/mapValuesarray spellings, andhasover aMapwithLowCardinalitykeys; each compares the indexed answer against an unindexed oracle.Workflow [PR]
Sync PR [sync-upstream/pr/114089]
Version info
26.8.1.1677(included in26.8and later)