Skip to content

Keep bloom_filter pruning for hasAll with a zero and for float arrayJoin equality - #124045

Open
aschoube wants to merge 12 commits into
ClickHouse:masterfrom
aschoube:bloom-filter-signed-zero-has-all-array-join
Open

aschoube wants to merge 12 commits into
ClickHouse:masterfrom
aschoube:bloom-filter-signed-zero-has-all-array-join

Conversation

@aschoube

@aschoube aschoube commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Closes #123744

Related: #123834
Related: #125652
Related: #125713

-0.0 = 0.0, but a bloom_filter index holds the hash of each value's bits, which differ for the two zeros. On master, a lookup of one zero skips the granules holding the other, so f = 0 returns [3] with the index and [1,3] without (#123744).

#123834 fixed this and was reverted in #125652, because 05325_bloom_filter_signed_zero failed with randomized map_serialization_version_for_zero_level_parts = 'with_buckets'. The cause was in the bucketed Map, not in the index: m[0.0] did not find a -0.0 key, which #125713 fixes. This PR reintroduces #123834 (commit "Reintroduce looking up both signed zeros in a bloom_filter index") and keeps the follow-up below.

Change

  • A zero is looked up as both 0.0 and -0.0 (Look up both signed zeros in a bloom_filter index #123834). hashWithFieldAndOtherZero adds the hash of the other zero for =, has, hasAny, mapContainsKey, mapContainsValue, mapKeys, and, on a bucketed Map, m[k] = v and m[k] IN (...). IN on a float column compares bits, so it still looks up only the given zero.
  • hasAll with a float zero keeps pruning. Look up both signed zeros in a bloom_filter index #123834 makes hasAll with a zero element not use the index, because FUNCTION_HAS_ALL needs every hash in the granule while one of the two zeros is enough. A granule matches only if every predicate entry matches, and under FUNCTION_HAS_ANY an entry matches if any of its hashes does. So one entry per element, with both hashes for a zero, is exactly hasAll.
  • arrayJoin(col) = constant uses the index for float elements. bloomFilterHashDomainMatches excluded floats because -0.0 equals 0.0 but hashes apart. With both zeros looked up through hashWithFieldAndOtherZero, the equals arm now allows a float element with an integer or float constant. convertFieldToType converts it exactly or returns Null, in which case the index is not used, for example 0.1 against Float32. The IN arm still excludes floats.
  • LEFT ARRAY JOIN padding. LEFT ARRAY JOIN pads an empty array with the default value, which the index does not hold. A constant equal to that value, such as 0.0 or -0.0 for a float element, does not use the index.

On the 103 rows of 05327 with index_granularity = 1, the bloom filter selects these granules:

Query master this PR
has(a, 0) 5, returns [0,101] instead of [0,100,101] 12
hasAll(a, [-0.0]) 7, returns [100] instead of [0,100,101] 12
hasAll(a, [0.0, 42.0]) 1, returns [101] instead of [100,101] 2
arrayJoin(a) = 42 not used (103) 11
arrayJoin(a) = 0.0 not used (103) 12
arrayJoin(b) = 0.5, Float32 not used (103) 4
arrayJoin(b) = 0.1, Float32 not used (103) not used (103)

05325_bloom_filter_signed_zero compares each zero lookup with and without the index, including m[0.0] = 'x' and m[0.0] IN ('x') on a table pinned to bucketed Map serialization, which return [3] instead of [1,3] on master. 05327_bloom_filter_signed_zero_has_all_array_join does the same for hasAll, hasAny and arrayJoin(col) = c, including -0.0/0.0, Float32 and the inexact 0.1, and checks with force_data_skipping_indices and max_rows_to_read that the index prunes. Both fail on master and pass here, also under randomized settings, and the bucketed m[0.0] queries give [1,3] with enable_analyzer = 0 and 1. Over 111 arrayJoin(col) = c, hasAll and hasAny queries on Array(Float64), Array(Float32) and Array(LowCardinality(Float64)), with constants such as -0.0, nan, inf, 0.1, 16777217, 9007199254740993, NULL and integers of different widths, the result with the index equals the result without it.

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

A bloom_filter index lookup of 0.0 or -0.0 no longer skips granules that hold the other zero, which returned wrong results, for example for WHERE f = 0 over a -0.0 value. The index is also used for arrayJoin(arr) = constant on a float array column, and keeps skipping granules for hasAll with a zero element, such as hasAll(arr, [0.0, 42.0]).


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

…rrayJoin(col) = c`

`hasAll` with a float zero element did not use the index, because
`FUNCTION_HAS_ALL` needs every hash in the granule while one of the two
zeros is enough. A granule matches only if every predicate entry matches,
and under `FUNCTION_HAS_ANY` an entry matches if any of its hashes does,
so one entry per element, with both hashes for a zero, is exactly
`hasAll`. `hasAll(a, [0.0, 42.0])` now skips granules without `42`.

`arrayJoin(col) = constant` did not use the index for float elements,
because `-0.0` equals `0.0` but hashes apart. With both zeros looked up,
the `equals` arm now allows a float element with an integer or float
constant. `convertFieldToType` converts it exactly or returns Null, in
which case the index is not used, for example `0.1` against `Float32`.
The `IN` arm still excludes floats.
@aschoube
aschoube marked this pull request as ready for review October 5, 2026 15:54
@clickhouse-gh clickhouse-gh Bot added the comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. label Oct 5, 2026
@aschoube
aschoube marked this pull request as draft October 6, 2026 00:39
@clickhouse-gh clickhouse-gh Bot added the external Author is not a member of the ClickHouse organization label Oct 6, 2026
@aschoube
aschoube marked this pull request as ready for review October 6, 2026 15:15
Suggestions from the review of ClickHouse#123834:

- `otherFloatZero` negates the zero instead of branching on its sign.
- `BloomFilterHash::getFieldHash` returns the hash of a `Field` as `UInt64`,
  and `hashWithField` wraps it in a `ColumnConst`. The signed-zero helpers use
  it instead of building a `ColumnConst` per hash and reading it back with
  `getUInt`.
- `hashWithColumnAndOtherZeros` adds the hash of a zero only when the constant
  array has the other zero but not this one, at most once, instead of once per
  zero element. `has_float_zero` stays set when both zeros are present, so
  `hasAll` still takes the per-element path.
- `hasAll` with a zero element adds the predicate entry for zeros once, not
  once per zero element.

`05327_bloom_filter_signed_zero_has_all_array_join` now also covers both zeros
and repeated zeros in the constant array of `hasAny` and `hasAll`.

Related: ClickHouse#123834

Co-authored-by: Copilot <[email protected]>
@aschoube

Copy link
Copy Markdown
Contributor Author

Could a maintainer add can be tested so CI runs on this PR?

@vdimir vdimir added the can be tested Allows running workflows for external contributors label Oct 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a9e52d7]

Summary: ❌

job_name test_name status info comment
Style check DROPPED
Build (arm_tidy, 1/4) DROPPED
Build (arm_tidy, 4/4) DROPPED

AI Review

Summary

This PR fixes signed-zero false negatives in bloom_filter lookups, preserves pruning for hasAll containing zero, and enables float arrayJoin equality lookups. No actionable findings remain at a9e52d72db2a7499d564073d77e1b533bfa412c5; both earlier padding findings are fixed, and the added bucketed-map coverage addresses the subsequent review request. The new hash-column representation reaches mayBeTrueOnGranule and maybeTrueOnBloomFilter, which accept both ColumnConst and ColumnUInt64; scalar equality, array searches, tuple predicates, and map lookups use disjunctive hash matching, while zero-containing hasAll uses conjunction across predicate entries. Both 05325_bloom_filter_signed_zero and 05327_bloom_filter_signed_zero_has_all_array_join pass in the current head's Fast test report.

Missing context / blind spots
  • ⚠️ Broader functional, sanitizer, and performance jobs are still pending in the current Praktika workflow. Runtime validation for this review relies on the completed Fast test report and the recorded before/after evidence in the PR discussion; no local build or test run was performed.
Final Verdict

Status: ✅ Approve. No new inline findings; no existing threads require replies or status changes.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 15, 2026
…-zero-has-all-array-join

# Conflicts:
#	src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp
This reverts commit cba98e5, which reverted ClickHouse#123834.
The helpers keep the versions of this branch. `05325_bloom_filter_signed_zero` pins `basic` `Map`
serialization: a bucketed `Map` does not find a `-0.0` key by `m[0.0]`, which is what failed with
randomized `map_serialization_version_for_zero_level_parts = 'with_buckets'`, see
ClickHouse#125713.

Related: ClickHouse#125652
@clickhouse-gh

clickhouse-gh Bot commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 32 queries analysed

Baseline selected using StressHouse version hint 26.11.1.42530; measured build ancestry could not be verified. Measured differences are not attributed to this PR. ⚙️ Master level shift inside the baseline window (~2026-10-18 06:15:53): baseline for 1 query restricted to the checks matching the selected baseline era.

no significant changes detected. K_source=6 K_base=26 flagged=0/65

clickbench

⚠️ 5 inconclusive

Flagged queries (5 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 9 not_sure 379 418 +10.2% <0.0001
⚠️ 13 not_sure 342 380 +11.3% <0.0001
⚠️ 16 not_sure 537 598 +11.5% <0.0001
⚠️ 32 not_sure 756 933 +23.4% <0.0001
⚠️ 34 not_sure 1037 1108 +6.8% <0.0001

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 115176a7-6ff0-4e74-85eb-7305fd51df5a
  • MIRAI run: 0220c73e-ff25-4910-9d0b-44769492f768
  • PR check IDs:
    • clickbench_491778_1792346236
    • clickbench_491890_1792346251
    • clickbench_491998_1792346267
    • tpch_adapted_1_official_492076_1792346270
    • tpch_adapted_1_official_492254_1792346304
    • tpch_adapted_1_official_492363_1792346312

…T ARRAY JOIN`

`isDefaultAt` compares the bits, so a `-0.0` constant was not treated as the
`+0.0` that `LEFT ARRAY JOIN` adds for an empty array. A granule with an empty
and a nonempty array without zero holds neither zero hash, and the index skipped
the padded rows matching `x = -0.0`.
@clickhouse-gh

clickhouse-gh Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a9e52d72d with master 213bd8dd0 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 35e918caf; 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.

Compile time of recompiled translation units

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

Job report

…rray-join' into bloom-filter-signed-zero-has-all-array-join
…ition

Use `accurateEquals` with the nested default so both signed zeros match padding, while nullable defaults retain their own semantics.
@aschoube

aschoube commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@groeneai can you review this and post review can you add a maintainer for visibility

@aschoube

aschoube commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@groeneai can you do a first level of review

@groeneai groeneai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I reviewed 399c7b57 merged into current master (6ab09677, debug build), against a master build. The index logic looks correct to me; two requests below.

What I measured:

  • #123744 reproduces on official 26.8.18.2 and 26.10.2.103 (f = 0 returns [3] with the index, [1,3] without). Both new tests fail on master and pass here.
  • 59 more queries comparing with and without the index on Array(Float64), Array(Float32) and Array(LowCardinality(Float64)) (NULL elements, three NaN bit patterns, inf, 16777217, 2^53 + 1, Int8/Int128/UInt256/Decimal/Bool/Nullable constants, indexOf, NOT, OR, empty hasAll/hasAny): all equal here, 15 differ on master.
  • The new padding guard: LEFT ARRAY JOIN ... WHERE x = <default> over granules mixing empty and nonempty arrays, for Int32, UInt8, Int128, Bool, String, FixedString(4) ('' and '\0\0\0\0'), LowCardinality(String), LowCardinality(Nullable(String)), Date, DateTime, DateTime64, UUID, IPv4, IPv6, Float32, Float64, LowCardinality(Float64): 39 of 39 equal with and without the index, same as master.

1. Two changed lookups have no test. I reverted only the hashWithFieldAndOtherZero calls in the mapKeys branch of traverseTreeIn and in the m[k] = v path: 05325 and 05327 still pass, while on a bucketed map m[0.0] = 'x' and m[0.0] IN ('x') return [3] instead of [1,3]. On a basic map, m[0.0] with a Float64 key throws ILLEGAL_TYPE_OF_ARGUMENT, so these paths are reached only on a bucketed map, and feca3f9 dropped the two queries. #125713 is merged, and 05325 gives the same reference with both settings set to with_buckets, so the "does not find a -0.0 key by m[0.0] yet" comment is stale. A table pinned to buckets covers both:

CREATE TABLE t_bf_signed_zero_bucketed (id UInt64, m Map(Float64, String), INDEX idx_m mapKeys(m) TYPE bloom_filter GRANULARITY 1)
ENGINE = MergeTree ORDER BY id
SETTINGS index_granularity = 1, map_serialization_version = 'with_buckets', map_serialization_version_for_zero_level_parts = 'with_buckets';
INSERT INTO t_bf_signed_zero_bucketed VALUES (1, map(-0.0, 'x')), (2, map(0.5, 'x')), (3, map(0.0, 'x'));
-- m[0.0] = 'x' and m[0.0] IN ('x'), with and without the index: [1,3] [1,3] here, [3] [1,3] on master

2. Changelog category. Against master this PR is again the #123744 fix, which is wrong results on 26.8 and 26.10. So I think it should be Bug Fix with Closes #123744, and the entry should say first that a bloom_filter lookup of 0.0 or -0.0 no longer skips granules holding the other zero. The table in the description compares with #123834, which is not on master. Optional: if the fix should be backported, the float arrayJoin(col) = c part could go to a separate PR so the backport carries only the fix.

I can't request reviewers on this repo, so for visibility: cc @Ergus, who reviewed #123834 and suggested the arrayJoin follow-up.

@aschoube

aschoube commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@groeneai I have added t_bf_signed_zero_bucketed to 05325_bloom_filter_signed_zero, pinned to map_serialization_version = 'with_buckets', with m[0.0] = 'x' and m[0.0] IN ('x') compared with and without the index, and removed the stale comment about #125713. The two queries set optimize_functions_to_subcolumns = 1, because without it m[0.0] throws ILLEGAL_TYPE_OF_ARGUMENT on a bucketed Map too.

i.e. on master the index skips the -0.0 row:

SELECT arraySort(groupArray(id)) FROM t_bf_signed_zero_bucketed WHERE m[0.0] = 'x'; -- [1,3], [3] on master
SELECT arraySort(groupArray(id)) FROM t_bf_signed_zero_bucketed WHERE m[0.0] IN ('x'); -- [1,3], [3] on master

I have updated the description: the category is Bug Fix with Closes #123744, the entry starts with the signed-zero fix, and the table compares with master. I have kept the float arrayJoin(col) = c part here; I can move it to a separate PR if the fix should be backported alone.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 9, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

I re-checked a9e52d7 (debug build of master 312c31c + this PR):

  • The map changes are now tested. Reverting hashWithFieldAndOtherZero in the traverseTreeIn mapKeys branch turns only m[0.0] IN ('x') red ([3] instead of [1,3]), and reverting it in the m[k] = v branch turns only m[0.0] = 'x' red. 05327 stays green under both reverts, so each hunk is caught by its own query.
  • 05325 and 05327 match their references on this build and differ on master, including both bucketed m[0.0] queries ([3] on master). CI on this head: 119 checks passed, none failed.
  • The description is right now: Bug Fix (wrong results on 26.8 and 26.10) with Closes #123744.

On the split: backport scope is the maintainers' call. My view is that the signed-zero and hasAll changes fix wrong results, while float arrayJoin(col) = c only adds index use where master does not use the index at all (not used (103) in your table, and force_data_skipping_indices fails on master). That part is an improvement, not a fix. So if this goes to 26.8/26.10, moving the arrayJoin part to its own PR keeps the backport limited to the fix.

Nothing else from my side.

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

can be tested Allows running workflows for external contributors comp-skip-index Skipping indexes (minmax, set, bloom) and their evaluation. external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bloom_filter index on float column skips granules holding -0.0 vs 0.0

3 participants