Repository navigation
Coerce the constant in the remaining two bloom_filter index paths - #117318
alexey-milovidov wants to merge 47 commits into
Conversation
The index hashes the exact bytes of a constant while the comparison it stands in for is padding-aware for the string family. Two paths still hashed the wrong byte length and pruned every granule: - a set coming from a subquery or a table keeps its own element type, and `castColumn` of a `FixedString` element to a `String` index strips the trailing zeros. A literal `IN` list is coerced to the left-hand-side type at set build and was already byte-exact. The `IN` path now applies the same `bloomFilterHashDomainMatches` guard `equals` uses. - `m['k'] = const` over a `mapValues` index hashed the raw constant against the map's value type, so a 2-byte `String` constant was hashed over 2 bytes while granules of `Map(String, FixedString(3))` hashed 3. It now goes through the same coercion as `equals` on a column, which is factored out into `coerceConstantForBloomFilterHash`. `01681_bloom_filter_nullable_column` relied on the over-pruning: a two-column set against a one-column left side is an error whichever `transform_null_in` is set, and with `use_skip_indexes = 0` too, but the index pruned every granule so the filter that raises it never ran. The two `transform_null_in = 0` queries now expect that error, like their `transform_null_in = 1` counterparts already did. Closes: #116407
|
Workflow [PR], commit [a5e5df1] Summary: ❌
AI ReviewSummaryThis PR fixes incorrect Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block Complete the Boolean hash-contract fixes (or track the existing sibling defect), guard the |
|
There is a third path with the same byte-length mismatch that this PR does not cover: a subquery/table set over a Verified on public master CREATE TABLE t_mv (m Map(String, String), INDEX bf mapValues(m) TYPE bloom_filter GRANULARITY 1)
ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 1;
INSERT INTO t_mv VALUES (map('k', 'V0')), (map('k', 'V0\0')), (map('k', 'xx'));
SELECT count() FROM t_mv WHERE m['k'] IN (SELECT 'V0'::FixedString(3)) SETTINGS use_skip_indexes = 0; -- 2
SELECT count() FROM t_mv WHERE m['k'] IN (SELECT 'V0'::FixedString(3)); -- 1The fix shape is the one this PR already applies to the single-column arm: guard the map-values set cast with For completeness, the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes3 object files changed (+84.43 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline. |
…dex-fixed-string-remaining-paths Conflict in `01681_bloom_filter_nullable_column.sql`: master's commit "Force enable_analyzer = 1 for IN column-count mismatch tests" already makes the two `transform_null_in = 0` queries expect `NUMBER_OF_COLUMNS_DOESNT_MATCH`, which is what this branch changed them to. Took master's queries and kept this branch's comment explaining why the error used to be masked by the index.
`traverseTreeIn` casts a prepared set to the map's value type with a plain `castColumn`, so a `FixedString` element over a `Map(String, String)` values index lost its trailing zeros before hashing and every granule was pruned - the same silent over-pruning this pull request removes from the plain-column set arm and from `m['k'] = const`. The arm now applies the same `bloomFilterHashDomainMatches` guard and declines instead of pruning. Test `05082_bloom_filter_index_fixed_string_set_and_map` covers both spellings of the set (a subquery and a table) against the `use_skip_indexes = 0` oracle, and keeps asserting that a same-type subquery set over a map still prunes (`Granules: 0/`).
…dex-fixed-string-remaining-paths
…ap value
`arrayElement` returns the value type's materialized default for a key that is
not in the map, and for `FixedString(N)` that default is `N` zero bytes, while
`DataTypeFixedString::getDefault` returns the empty `Field`. The guard in
`traverseTreeEquals` compared the constant against the raw `getDefault`, so it
stayed inactive for `m['absent'] = toFixedString('', 3)` and both map arms of
the `bloom_filter` index pruned every granule where the key is absent, even
though those rows match the comparison.
Compare against the materialized default the way the `IN` path already does,
keeping the raw default as well so no case that previously declined the index
starts using it.
Verified with a control binary: without the fix the new cases return `0` for
both the `mapValues` and the `mapKeys` index against a `use_skip_indexes = 0`
oracle of `3`.
The test is renumbered to `05175` because master added
`05082_native_arrow_ipc_union_visibility` in the meantime.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117318&sha=7d0ef3c68ece9d93f6808df0460834ff304a21ca&name_0=PR&name_1=Stress%20test%20%28arm_release%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The only red at that run was |
|
That
That is the same path as the run you attached to #116047 on 09-07 ( No fix PR exists for it yet, mine or anyone else's. I am starting one now and will link it here. It does not need the design decision that stalled the replicated arm: what the merge predicate is missing here is the future data version of an in-flight merge, which is process-local and reachable under the Since it explains that stall: I posted the design fork for the replicated arm at #98898 (comment) two days after that issue was closed, so it never reached you. It is still the last comment there. |
`05175` is already taken by the open #117318, which adds `05175_bloom_filter_index_fixed_string_set_and_map`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…dex-fixed-string-remaining-paths
The guard that keeps the `bloom_filter` index away from a constant a missing map key can match compared the constant only against the defaults of its own type. `equals` zero-pads the shorter side for the string family, so over `Map(String, FixedString(3))` the `String` constant `'\0'` (or any all-zero string of any length) is equal to the `FixedString(3)` default a missing key materializes as, although it is no default of `String`. The `mapKeys` arm hashed only the key and the `mapValues` arm hashed the coerced `'\0\0\0'`, so both pruned the granules where the key is absent. The question is now asked of `equals` itself, with the map's value type on the left and the constant's type on the right, exactly as in the query, and the index declines when the value type's default compares equal. The two previous checks are kept, so nothing that declined before starts using the index. Test cases for `'\0'` and `'\0\0\0\0'` on both arms against the `use_skip_indexes = 0` oracle, plus a control that `Map(String, String)`, whose comparison is exact, still prunes for `'\0'`. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ue type default `Set::execute` casts the left column to the set's element type, so a missing key's default of the map value type can match a set element that is not the set's own default, e.g. `0` of `UInt8` against `IN (SELECT '0')`. Probe the set with that default too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…dex-fixed-string-remaining-paths
…d_map` Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…fault of another type `Set::execute` converts the synthetic missing-key default leniently, but the conversion of a `String` to an `Enum` still throws `UNKNOWN_ELEMENT_OF_ENUM` for an unknown label (`''`), so a valid `m['k'] IN (SELECT <Enum>)` query over `Map(String, String)` with a `mapKeys` or `mapValues` index threw. Decline the index when the set element type contains an `Enum` and the map value type is not that same type. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged the latest
|
|
🕵 Status of |
|
The fix is #126200 (mine, open, waiting for review), and this job.log is the case it covers: the readiness probe ( The read-only CI logs endpoint is out of memory. Probed just now, It affects every PR: CIDB has no successful |
|
🕵 Thanks @groeneai. #126200 is still open, so the |
|
🕵 Merged the latest |
…index `convertFieldToType` accepts only a `UInt64` `Field` for a `DateTime`, so `d = toInt64(1)` over a `DateTime` column with a `bloom_filter` index threw `TYPE_MISMATCH`, and the coercion of the constant newly applied to the `mapValues` path made `m['k'] = toInt64(1)` throw the same way. `equals` compares the two numerically, so convert a non-negative `Int64` to `UInt64` first, and decline the index for a negative one, which equals no stored value. Address review: #117318 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged the latest |
05076 and 05077 are already taken by open pull requests ClickHouse#118128 and ClickHouse#118003, and 05081/05082 by ClickHouse#117314/ClickHouse#117318, so a merge of any of them would collide. Co-Authored-By: Claude Opus 5 <[email protected]>
# Conflicts: # src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp
|
🕵 Merged the latest |
`arrayElement(m, key)` makes its result `Nullable` when the key argument is
nullable, but for a non-NULL key that is absent it still returns the default
of the map's own value type. The `equals` and `IN` paths of the `bloom_filter`
index derived the missing-key default from the result type, probed with `NULL`
and concluded the missing key could not match, so `m[toNullable('absent')] = '\0'`
over `Map(String, FixedString(3))` pruned every granule. The same applied to the
`Enum` zero check of the `IN` path. Read the value type from the `Map` type.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…adroom baseline `master_baseline` took the nearest commit of the run's master chain whose `Build (amd_msan)` report existed and skipped every commit without one. A master job uploads its report only in `post_run`, so a parent that is still building looked like one that never builds, and the PR was compared with an older commit. On 2026-11-14 ClickHouse#117346 (`Use clang-23`) moved the msan layout by -16.23 MiB; its own master build ran until 20:42Z, and ClickHouse#124068, ClickHouse#131668 and ClickHouse#117318, checked a few seconds earlier, were compared with the commit before it and failed with exactly master's delta. Apply the rule the performance delta gate uses for the same walk (`classify_missing_prev_master_run`, 8b06c76): when the job report is missing, read the commit's MasterCI summary and skip the commit only when MasterCI never ran there, the run has no such job, or the job is `SKIPPED`. Any other status, a report without the headroom row, or a lookup error other than 403/404 stops the walk: no baseline (the header names the commit and its status) or the existing `ERROR`. A PR success without a baseline because the walk stopped is not cached, since master's state is not a build digest input. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nvertFieldToType` rejects `coerceConstantForBloomFilterHash` is shared by `equals` on an indexed column and by `m['k'] = const` over a `mapValues` `bloom_filter` index. Two problems were reported in review: 1. The non-strict `convertFieldToType` clamps any non-zero integer to `true` for a `Bool`, while a `Bool` column can hold another byte (e.g. through `reinterpret`) and `equals` compares it numerically. The constant 2 was hashed as 1 and the granule holding the byte 2 was pruned. The integer that is compared is now hashed, and the index declines for one outside of `UInt8`. 2. `convertFieldToType` throws `TYPE_MISMATCH` for pairs that `equals` accepts: a `DateTime` with a `Float64` or a wide integer, and an `IPv4` with an `IPv6` in both directions. A `Float64` that is a whole number of seconds fitting `UInt32` is now converted, and the index declines for the rest instead of making a query fail that succeeds without the index. Test `05839_bloom_filter_bool_datetime_ip_constant` covers both paths against the `use_skip_indexes = 0` oracle. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…IPv4` constant Three more cases where the `bloom_filter` index did not match the comparison it stands in for: - `equals` compares a `DateTime64` with a floating-point constant as `Float64`, so several stored ticks equal one constant, while the index hashed only the one tick the constant converts to. `coerceConstantForBloomFilterHash` now declines the pair. - `Set` converts the left-hand side to the type of the set, and a conversion to `Bool` collapses every non-zero number to `true`, so `2 IN (SELECT true)` holds while the index hashed only `1`. The `IN` paths (plain column, `mapValues`, `arrayJoin`) now go through `bloomFilterSetHashDomainMatches`, which declines whenever a `Bool` is involved. - `convertFieldToType` throws `TYPE_MISMATCH` for an `IPv4` constant against a numeric index, although `equals` compares the address numerically. The number is now hashed. Covered by `05872_bloom_filter_float_datetime64_bool_set_ipv4_constant` against the `use_skip_indexes = 0` oracle. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…e `EXPLAIN` layout With parallel replicas the plan is printed with tree-drawing prefixes (`│ Granules: 1/2`), which `trim` does not remove, so the test failed in the `ParallelReplicas` stateless job. Extract the `Granules` counter itself instead. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=117318&sha=a3074625560464e8073315995ab2b15e894f0ee0&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20plan-based%2C%20s3%20storage%2C%20parallel%29 #117318 Co-Authored-By: Claude Fable 5.2 <[email protected]>
| if (!set_type) | ||
| return false; | ||
|
|
||
| auto has_bool = [](const IDataType & type) { return isBool(type.getPtr()); }; |
There was a problem hiding this comment.
[Blocker] Include Boolean customizations in the set hash-domain check
isBool checks the name Bool, but SimpleAggregateFunction(any, Bool) is a customized UInt8 with no child types, so this walk misses it. Its cast still collapses nonzero numbers to 1 (FunctionsConversion.h also checks isSimpleAggregateFunctionOfBool). For example:
CREATE TABLE t (v UInt16, INDEX bf v TYPE bloom_filter(0.0001) GRANULARITY 1)
ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 1;
INSERT INTO t VALUES (1), (2);
SELECT count() FROM t
WHERE v IN (SELECT CAST(true AS SimpleAggregateFunction(any, Bool)));Tracing Set::castToKeyType, both rows match because UInt16 is converted to the Boolean set type. This guard admits the integer pair, however, and the reverse cast hashes only 1, so the granule containing 2 can be dropped. The same hole affects the map-values and arrayJoin set paths.
Please recognize Boolean customizations, using the same predicate as the conversion code, and cover this case against use_skip_indexes = 0. The equality helper's isBool(actual_type) check has the same representation gap and should use that predicate too.
| /// non-strict `convertFieldToType` clamps any non-zero integer to `true`, so `2` would be hashed | ||
| /// as `1` and the granule holding the byte `2` pruned. Hash the number that is compared; one | ||
| /// outside of `UInt8` equals no stored value, and the index declines. | ||
| if (isBool(actual_type) && !(value_type && isBool(removeLowCardinalityAndNullable(value_type)))) |
There was a problem hiding this comment.
[Blocker] Apply the Boolean equality coercion to the arrayJoin path too
The new helper preserves an integer constant when comparing it with a Bool byte, but traverseTreeEquals still calls plain convertFieldToType at line 1731 for arrayJoin equality. Its preceding bloomFilterHashDomainMatches admits cross-integer types, including Bool, so this path still clamps toInt64(2) to 1 before hashing:
CREATE TABLE t (a Array(Bool), INDEX bf a TYPE bloom_filter(0.0001) GRANULARITY 1)
ENGINE = MergeTree ORDER BY tuple() SETTINGS index_granularity = 1;
INSERT INTO t SELECT [reinterpret(toUInt8(2), 'Bool')];
SELECT count() FROM t WHERE arrayJoin(a) = toInt64(2);The stored element and runtime numeric comparison use byte 2, while the index probes byte 1, so a matching row can be pruned. This is an existing sibling of the Boolean equality bug being fixed here. Please route admitted arrayJoin equality probes through the same coercion (retaining its domain and padded-element guards), or link a tracking issue if handled separately, and add this full-scan comparison.
| case Field::Types::Float64: | ||
| { | ||
| UInt32 seconds = 0; | ||
| if (!accurate::convertNumeric<Float64, UInt32, true>(value_field.safeGet<Float64>(), seconds)) |
There was a problem hiding this comment.
[Blocker] Reject NaN before converting the floating constant to UInt32
accurate::convertNumeric does not safely reject a floating NaN for an integer target: both range comparisons in Core/AccurateComparison.h return false, then it executes static_cast<UInt32>(value). That conversion is undefined behavior; returning false from the later equality check does not undo it.
A valid predicate such as m['k'] = nan over the DateTime map in the new test reaches this call: the missing-key comparison is false and the constant is a Float64 field. A plain indexed DateTime column reaches it too. The numeric conversion helper in convertFieldToType.cpp already checks isFinite before calling this primitive for precisely this reason.
Please decline the index for a non-finite constant before this call, or use the guarded numeric conversion path. These boundary inputs were traced in source; no runtime reproduction was run in this CI job.
Closes: #116407
Related: #112206
Related: #117021
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a
bloom_filterskip index silently dropping matching rows for aString/FixedStringconstantin the paths the #112206 fix did not cover: a set coming from a subquery or a table,
m['k'] = constover a
mapValuesindex, and a subquery/table set over amapValuesindex.Description
The index hashes the exact bytes of a constant, while the comparison it stands in for is padding-aware
for the string family. Two remaining paths hashed the wrong byte length, so no granule matched and the
query returned fewer rows than a full scan of the same filter:
IN(traverseTreeIn). The set keeps its own element type and is brought to theindex type with
castColumn, which strips aFixedString's trailing zeros — the granule sidehashed the stored bytes. A literal
IN (...)was unaffected: the literal is coerced to theleft-hand-side type at set build. The path now applies the same
bloomFilterHashDomainMatchesguard
traverseTreeEqualsuses, so the index declines instead of pruning.arrayElementover amapValuesindex. The raw constant was hashed against the map's valuetype with no coercion, so a 2-byte
Stringconstant was hashed over 2 bytes while granules ofMap(String, FixedString(3))hashed 3, and every granule was pruned. It now goes through the samerecipe as
equalson a column — which is factored out of that path intocoerceConstantForBloomFilterHashso the two cannot drift apart. Coercion (rather than declining)keeps the pruning: the padded form is exactly what the granule holds.
One existing test relied on the over-pruning. In
01681_bloom_filter_nullable_column, a two-column setagainst a one-column left side is an error whichever
transform_null_inis set — and withuse_skip_indexes = 0as well — but the index pruned every granule, so the filter that raises it neverran and the query "succeeded" with no rows. The two
transform_null_in = 0queries now expect the sameNUMBER_OF_COLUMNS_DOESNT_MATCHtheirtransform_null_in = 1counterparts already did. This is thebehaviour the existing comment in
coerceStringFieldLikeSearchFunctionasks for: decline the index sothe error stays reachable instead of turning into silently pruned granules.
A subquery/table set over a
mapValuesindex - the combination of the two above, added afterreview. The map arm of
traverseTreeIncasts the set column to the map's value type with the sameplain
castColumn, so aFixedStringelement over aMap(String, String)values index hashed thestripped bytes and pruned every granule. It now applies the same
bloomFilterHashDomainMatchesguard as the plain-column arm.
The missing-key guard for
m['k'] = const, added after review.arrayElementreturns thevalue type's materialized default for a key that is not in the map, and for
FixedString(N)thatdefault is
Nzero bytes, whileDataTypeFixedString::getDefaultreturns the emptyField. Theguard compared the constant against the raw
getDefault, so it stayed inactive form['absent'] = toFixedString('', 3)and both map arms pruned every granule where the key isabsent. It now compares against the materialized default the way the
INpath already does, andkeeps the raw default comparison so nothing that previously declined the index starts using it.
Both of those are still defaults of the constant's type, while the comparison happens in the
map's value type:
equalszero-pads the shorter side of the string family, so overMap(String, FixedString(3))theStringconstant'\0'(or any all-zero string of any length)equals a missing key although it is no default of
String. The guard therefore also asksequalsitself, with the map's value type and the constant's type as in the query, whether the value type's
default compares equal to the constant, and declines the index when it does.
Constants the shared recipe converted wrongly or refused, added after review. The non-strict
convertFieldToTypeclamps any non-zero integer totruefor aBool, while aBoolcolumn canhold another byte and
equalscompares it numerically, som['k'] = 2pruned the granule holdingthe byte 2; the integer that is compared is now hashed.
convertFieldToTypealso throwsTYPE_MISMATCHfor pairsequalsaccepts - aDateTimewith aFloat64or a wide integer, anIPv4with anIPv6in both directions - so a query that succeeds without the index failed withit. A whole-second
Float64is now converted, and the index declines for the rest. Covered by05839_bloom_filter_bool_datetime_ip_constant.Three more comparisons the hash did not stand for, added after review.
equalscompares aDateTime64with a floating-point constant asFloat64, so several stored ticks equal oneconstant while only one was hashed; the index now declines.
Setconverts the left-hand side tothe type of the set, and a conversion to
Boolcollapses every non-zero number totrue, so2 IN (SELECT true)holds while only1was hashed; theINpaths now decline whenever aBoolis involved. An
IPv4constant against a numeric index threwTYPE_MISMATCHalthoughequalscompares the address numerically; the number is now hashed. Covered by
05872_bloom_filter_float_datetime64_bool_set_ipv4_constant.Test
05175_bloom_filter_index_fixed_string_set_and_mapcovers all four paths against theuse_skip_indexes = 0oracle, and asserts that a same-type subquery set and a non-defaultFixedStringconstant still prune (Granules: 0/), both over a plain column and over a map.Workflow [PR]
Sync PR [sync-upstream/pr/117318]