Skip to content

Coerce the constant in the remaining two bloom_filter index paths - #117318

Open
alexey-milovidov wants to merge 47 commits into
masterfrom
fix-bloom-filter-index-fixed-string-remaining-paths
Open

alexey-milovidov wants to merge 47 commits into
masterfrom
fix-bloom-filter-index-fixed-string-remaining-paths

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Closes: #116407
Related: #112206
Related: #117021

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a bloom_filter skip index silently dropping matching rows for a String/FixedString constant
in the paths the #112206 fix did not cover: a set coming from a subquery or a table, m['k'] = const
over a mapValues index, and a subquery/table set over a mapValues index.

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:

  1. Subquery/table IN (traverseTreeIn). The set keeps its own element type and is brought to the
    index type with castColumn, which strips a FixedString's trailing zeros — the granule side
    hashed the stored bytes. A literal IN (...) was unaffected: the literal is coerced to the
    left-hand-side type at set build. The path now applies the same bloomFilterHashDomainMatches
    guard traverseTreeEquals uses, so the index declines instead of pruning.
  2. arrayElement over a mapValues index. The raw constant was hashed against the map's value
    type with no coercion, so a 2-byte String constant was hashed over 2 bytes while granules of
    Map(String, FixedString(3)) hashed 3, and every granule was pruned. It now goes through the same
    recipe as equals on a column — which is factored out of that path into
    coerceConstantForBloomFilterHash so 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 set
against a one-column left side is an error whichever transform_null_in is set — and with
use_skip_indexes = 0 as well — but the index pruned every granule, so the filter that raises it never
ran and the query "succeeded" with no rows. The two transform_null_in = 0 queries now expect the same
NUMBER_OF_COLUMNS_DOESNT_MATCH their transform_null_in = 1 counterparts already did. This is the
behaviour the existing comment in coerceStringFieldLikeSearchFunction asks for: decline the index so
the error stays reachable instead of turning into silently pruned granules.

  1. A subquery/table set over a mapValues index - the combination of the two above, added after
    review. The map arm of traverseTreeIn casts the set column to the map's value type with the same
    plain castColumn, so a FixedString element over a Map(String, String) values index hashed the
    stripped bytes and pruned every granule. It now applies the same bloomFilterHashDomainMatches
    guard as the plain-column arm.

  2. The missing-key guard for m['k'] = const, added after review. 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 compared the constant against the raw getDefault, so it stayed inactive for
    m['absent'] = toFixedString('', 3) and both map arms pruned every granule where the key is
    absent. It now compares against the materialized default the way the IN path already does, and
    keeps 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: equals zero-pads the shorter side of the string family, so over
    Map(String, FixedString(3)) the String constant '\0' (or any all-zero string of any length)
    equals a missing key although it is no default of String. The guard therefore also asks equals
    itself, 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.

  3. Constants the shared recipe converted wrongly or refused, added after review. The non-strict
    convertFieldToType clamps any non-zero integer to true for a Bool, while a Bool column can
    hold another byte and equals compares it numerically, so m['k'] = 2 pruned the granule holding
    the byte 2; the integer that is compared is now hashed. convertFieldToType also throws
    TYPE_MISMATCH for pairs equals accepts - a DateTime with a Float64 or a wide integer, an
    IPv4 with an IPv6 in both directions - so a query that succeeds without the index failed with
    it. A whole-second Float64 is now converted, and the index declines for the rest. Covered by
    05839_bloom_filter_bool_datetime_ip_constant.

  4. Three more comparisons the hash did not stand for, added after review. equals compares a
    DateTime64 with a floating-point constant as Float64, so several stored ticks equal one
    constant while only one was hashed; the index now declines. 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 only 1 was hashed; the IN paths now decline whenever a Bool
    is involved. An IPv4 constant against a numeric index threw TYPE_MISMATCH although equals
    compares 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_map covers all four paths against the
use_skip_indexes = 0 oracle, and asserts that a same-type subquery set and a non-default
FixedString constant still prune (Granules: 0/), both over a plain column and over a map.


Workflow [PR]
Sync PR [sync-upstream/pr/117318]

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
@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a5e5df1]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

This PR fixes incorrect bloom_filter pruning for string constants and map lookups, and extends constant conversion coverage. The previously reported cases are addressed, but Boolean conversions still have uncovered representations and an equality entrypoint, and the new DateTime floating conversion can execute undefined behavior.

Missing context / blind spots
  • ⚠️ Findings below are concrete source traces at PR head a5e5df16113941544f7c32004bd6f59d3b052ce1, not local runtime reproductions. This CI job has no ClickHouse binary and forbids nested test runs. The fetched CI reports are green; focused coverage of these boundary inputs is still needed.
Findings

❌ Blockers

  1. Boolean set guard, line 960: isBool misses SimpleAggregateFunction(any, Bool), whose customized numeric type has no Boolean child for anyInTypeTree to visit. For an indexed UInt16 column containing 1 and 2, v IN (SELECT CAST(true AS SimpleAggregateFunction(any, Bool))) converts both values to true at runtime, but index analysis hashes only 1 and can prune the matching 2. This affects the plain-column, map-values and arrayJoin set consumers. Use the conversion code's Boolean-customization predicate; apply it to the equality helper's Boolean check too.

  2. Boolean equality coercion, line 1080: The new coercion is used for scalar and map equality, while arrayJoin equality still calls plain convertFieldToType at line 1731. For Array(Bool) holding reinterpret(toUInt8(2), 'Bool'), arrayJoin(a) = toInt64(2) compares byte 2 at runtime but probes hash 1, so it can lose the row. Share the coercion across equality consumers while retaining their existing domain and padding checks, or link a tracking issue for this existing sibling defect.

  3. Floating DateTime conversion, line 1045: A NaN constant passes both range comparisons inside accurate::convertNumeric and reaches static_cast<UInt32>(NaN), which is undefined behavior. Both plain DateTime equality and map-value equality can reach this new call. Check isFinite first, as the numeric helper in convertFieldToType.cpp already does, or reuse that guarded conversion.

Tests
  • ⚠️ Add a subquery-set regression with SimpleAggregateFunction(any, Bool) and ordinary nonzero integer values, comparing indexed results with use_skip_indexes = 0 for the affected set consumers.
  • ⚠️ Add arrayJoin equality coverage for a stored Boolean byte 2 against an Int64 constant 2, using the full scan as the oracle.
  • ⚠️ Verify that NaN predicates on both DateTime equality consumers decline before any floating-to-integer cast.
Final Verdict

Status: ❌ Block

Complete the Boolean hash-contract fixes (or track the existing sibling defect), guard the NaN conversion, and validate the focused cases above.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 31, 2026
@zlareb1

zlareb1 commented Aug 31, 2026

Copy link
Copy Markdown
Member

There is a third path with the same byte-length mismatch that this PR does not cover: a subquery/table set over a mapValues index — the combination of the PR's two fixes. traverseTreeIn's map arm casts the set column with a plain castColumn and no bloomFilterHashDomainMatches guard (the else if (map_info->has_values_index) branch, MergeTreeIndexBloomFilter.cpp around line 737 at this PR's head), so a FixedString set element over a Map(String, String) values index hashes the wrong byte form and prunes granules the comparison would match.

Verified on public master 26.9.1.417 (and 24.8/25.8/26.8 on the fiddle — long-standing):

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));                               -- 1

The fix shape is the one this PR already applies to the single-column arm: guard the map-values set cast with bloomFilterHashDomainMatches(type, array_nested_type) before the castColumn, so the index declines instead of pruning.

For completeness, the mapKeys side of both IN and equals checks out clean in the same rig: a short String key over Map(FixedString(3), String) (m['k'] = 'v2', m['k'] IN ('v2', 'zz')) returns the same counts with and without the index, because hashWithField brings the key Field to the index type — consistent with the PR's note that the key is hashed in its stored form.

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a5e5df161 with master 13091b141 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

3 object files changed (+84.43 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp.o 506.30 KiB 590.72 KiB +84.43 KiB (+16.68%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

7 translation units recompiled, 12 s compile time in total, 7 of them have a recent master baseline.

Job report

…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/`).
@clickhouse-gh clickhouse-gh Bot added the comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. label Sep 4, 2026
alexey-milovidov and others added 2 commits September 10, 2026 05:35
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @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 Stress test (arm_release) with Logical error: Found patch part A (min data version: B, max data version: C) that intersects mutation with version D — patch parts versus mutation versions, unrelated to this bloom_filter index change. It is tracked by the open issue #116047, which has no fix on master yet.

@groeneai

Copy link
Copy Markdown
Collaborator

That arm_release red is the plain (non-replicated) MergeTree arm of #116047, not the ReplicatedMergeTree arm that #115064 closed. Frame probes on that run's own context, with a liveness control on the message itself:

probe value
Found patch part (control) 1
StorageMergeTree::MutationsSnapshot 1
MutatePlainMergeTreeTask 1
ReplicatedMergeTreeQueue / StorageReplicatedMergeTree 0
assertNoPatchesForParts 0
findDataVersionInRange (the #115064 symbol) 0

Found patch part patch-3bba1aecd068f93ef4b30beb7f356b8f-0_9_42_2_40 (min data version: 7, max data version: 40) that intersects mutation with version 24, thrown from patchHasHigherDataVersion below StorageMergeTree::getMutationsSnapshot in a mutate-part task.

That is the same path as the run you attached to #116047 on 09-07 (42ffeb0839d), which has an identical probe profile. That head is behind_by = 0 against 6c665da24d6 (#113941, merged 09-04 into the same functions), so #113941 does not cover this arm either.

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 merge_mutate_lock it already holds, whereas the replicated arm needed a fact no single replica holds.

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.

alexey-milovidov added a commit that referenced this pull request Sep 10, 2026
`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]>
alexey-milovidov and others added 3 commits September 17, 2026 20:21
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]>
alexey-milovidov and others added 4 commits September 19, 2026 20:49
…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]>
alexey-milovidov and others added 2 commits October 26, 2026 16:48
…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged the latest master (clean merge, no changes to the bloom filter code). Both CI failures on 64a5339 are unrelated to this PR:

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status of f8df7772: every check passes except Build profile diff. That job failed with LogClusterNotReady: the endpoint never became ready while querying the CI logs cluster, which is infrastructure and unrelated to the bloom filter change. The open fix for this job's readiness probe is #126200.
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/117318/f8df77723bc9dc23852a3dd4a10fd6c36aa09324/pr/build_profile_diff/job.log and provide a fix in a separate PR. If the fix is already in progress, link it here (it may be #126200).
The branch still merges cleanly with the latest master, and there are no unresolved review threads.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is #126200 (mine, open, waiting for review), and this job.log is the case it covers: the readiness probe (SELECT 1 in LogCluster.is_ready, reached from has_pr_data through select) got a non-2xx answer on all 8 attempts between 15:40 and 15:43 UTC, so select raised LogClusterNotReady.

The read-only CI logs endpoint is out of memory. Probed just now, SELECT 1 returns HTTP 500 with code 241 (RSS 213.06 GiB, limit 212.40 GiB). With #126200, probes rejected for load (codes 202/241) raise LogClusterUnavailable, and the job ends green with CI logs cluster unavailable, nothing compared.

It affects every PR: CIDB has no successful Build profile diff since 2026-10-26 22:42 UTC (473 failed runs since). The memory pressure on the logs cluster itself is outside this repository.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai. #126200 is still open, so the Build profile diff failure (LogClusterNotReady, CI logs cluster out of memory) will stay red on every PR until it lands; merging master into this branch would not clear it. Every other check on f8df7772 passes, the branch is mergeable, and all review threads are resolved, so no change is needed here.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged the latest master (8afefe0). The merge was clean. master's a3d7b0c switched the Map subcolumn shadowing check from a NameSet to a lazy IsShadowingColumn callback inside MergeTreeIndexBloomFilter.cpp, and it fits with this PR's changes without edits. After the merge, clickhouse builds, and these tests pass locally: 05175_bloom_filter_index_fixed_string_set_and_map, 05448_bloom_filter_map_in_enum_set, 01681_bloom_filter_nullable_column, 05061_map_enum_key_bloom_filter and 05331_map_enum_negative_bloom_filter_in. The only red check on the previous head was Build profile diff (LogClusterNotReady). It is unrelated to this PR, and its fix, #126200, is still open. There are no unresolved review threads.

…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]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged the latest master (c05f25f, clean merge). master changed MergeTreeIndexBloomFilter.cpp in 5335edb (malformed granule handling), and it combines with this PR without edits. The PR's diff against master is unchanged. After the merge, clickhouse builds and the four tests of this PR (01681, 05175, 05448, 05473) pass locally. There are no unresolved review threads.

ringerc pushed a commit to ringerc/ClickHouse-patches that referenced this pull request Nov 9, 2026
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
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged the latest master (edfbc33) as 2008e2b. The only conflict was in the include list of MergeTreeIndexBloomFilter.cpp: master added Functions/FunctionsMiscellaneous.h and this PR added DataTypes/TypeTree.h and Functions/FunctionFactory.h, so the merge keeps all three. master also changed bloom_filter index matching to compare whole expressions (ad5361f, ed214d5, 903c7e4), and those changes merged without conflicts. The merged MergeTreeIndexBloomFilter.cpp compiles. The full binary was not rebuilt locally, so CI will check the tests.

alexey-milovidov and others added 2 commits November 18, 2026 13:05
`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]>
arwenizEr pushed a commit to arwenizEr/ClickHouse that referenced this pull request Nov 18, 2026
…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]>
alexey-milovidov and others added 2 commits November 21, 2026 11:27
…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]>
alexey-milovidov and others added 3 commits November 24, 2026 10:56
…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()); };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

3 participants