Repository navigation
Description
Describe what's wrong
- Rows are silently dropped when filtering a float column equal to zero with a
bloom_filterindex. - Trigger is
f = 0,f = -0.0,has,hasAny, ormapContainsKeyoverFloat64/Array(Float64)/Map(Float64, String). -0.0and0.0compare equal, so both should match, but only the granule matching the exact bit pattern is kept.INis unaffected since it compares bit-exact values; disablinguse_skip_indexesreturns correct rows.
Root cause: MergeTreeIndexBloomFilter.cpp:1132 and related paths hash only the bitwise representation of the float constant, so -0.0 and 0.0 hash differently even though equals treats them as the same value. The existing float exclusion in bloomFilterHashDomainMatches (:600) is wired only into the arrayJoin paths, not into scalar equals, has, hasAny/hasAll, or mapContainsKey.
Analysis details (evidence, affected locations, impact)
Why we believe this is a bug: - The index stores DefaultHash64 of the float's bits (BloomFilterHash.h:41, HashTable/Hash.h:237-245), so -0.0 and 0.0 hash apart.
traverseTreeEqualshashes the converted constant the same way for scalarequals(MergeTreeIndexBloomFilter.cpp:1132),has(const, col)(:1073),has(col, const)(:1059),hasAny/hasAll(:1090),mapContains*(:1205),m[k] = v(:1271).- Only the
arrayJoinpaths decline floats, viabloomFilterHashDomainMatches(:591-601), whose comment names this exact reason.
Affected locations:
src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp:1132— scalarequals: single bitwise hash of the float constantsrc/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp:1073—has(<const array>, col)src/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp:1059—has(col, const)/indexOfsrc/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp:1090—hasAny/hasAllsrc/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp:1205—mapContainsKey/mapContainsValuesrc/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp:1271—m[k] = vover a keys/values indexsrc/Storages/MergeTree/MergeTreeIndexBloomFilter.cpp:600— float exclusion applied only onarrayJoinpathssrc/Interpreters/BloomFilterHash.h:41—DefaultHash64over the float's bits
Impact: Silent row loss for equality-style filters against a float zero on tables with a bloom_filter index on a float column (or float Array/Map) holding the other zero. With alternating signs, 5 of 10 rows were lost for both f = 0 and f = -0.0. IN is unaffected (bit-exact on both sides).
Does it reproduce on most recent release?
Confirmed on master (5d1eb5c770b1); not checked on a release.
How to reproduce
Use index_granularity = 1 so each row sits in its own granule, making the dropped rows visible.
-- Test: `-0.0 = 0.0` holds, so a `bloom_filter` index on a float column must not skip the granule holding the other zero.
DROP TABLE IF EXISTS t_bf_signed_zero;
CREATE TABLE t_bf_signed_zero
(
id UInt64,
f Float64,
a Array(Float64),
m Map(Float64, String),
INDEX idx_f f TYPE bloom_filter GRANULARITY 1,
INDEX idx_a a TYPE bloom_filter GRANULARITY 1,
INDEX idx_m mapKeys(m) TYPE bloom_filter GRANULARITY 1
)
ENGINE = MergeTree ORDER BY id SETTINGS index_granularity = 1;
INSERT INTO t_bf_signed_zero VALUES (1, -0.0, [-0.0], map(-0.0, 'x')), (2, 0.5, [0.5], map(0.5, 'x')), (3, 0.0, [0.0], map(0.0, 'x'));
SET use_skip_indexes = 1;
SELECT arraySort(groupArray(id)) FROM t_bf_signed_zero WHERE f = 0;
SELECT arraySort(groupArray(id)) FROM t_bf_signed_zero WHERE f = -0.0;
SELECT arraySort(groupArray(id)) FROM t_bf_signed_zero WHERE has([0.0, 0.5], f);
SELECT arraySort(groupArray(id)) FROM t_bf_signed_zero WHERE has(a, 0);
SELECT arraySort(groupArray(id)) FROM t_bf_signed_zero WHERE hasAny(a, [0.0]);
SELECT arraySort(groupArray(id)) FROM t_bf_signed_zero WHERE mapContainsKey(m, 0.0);
DROP TABLE t_bf_signed_zero;Verified: this block reproduces on current master (5d1eb5c770b1) when pasted as is.
Expected behavior
A bloom_filter index must not prune the granule holding the other zero when filtering for equality against a float zero.
Expected output of the reproducer above:
[1,3]
[1,3]
[1,2,3]
[1,3]
[1,3]
[1,3]
Error message and/or stacktrace
Granules holding the other zero representation are skipped, silently losing matching rows.
Actual output of the reproducer above on master (5d1eb5c770b1):
[3]
[1]
[2,3]
[3]
[3]
[3]
Suggested fix
In traverseTreeEquals, when the converted float constant (or an element of a constant array / map key) is a zero, look up both hash(0.0) and hash(-0.0) (FUNCTION_HAS_ANY over both); decline hasAll with a zero element. Keeps pruning and the index format. Normalizing -0.0 at hash time alone is not enough: existing parts already store hash(-0.0). Cheapest alternative: reuse the bloomFilterHashDomainMatches float exclusion on these paths, losing bloom-filter pruning for every float equality.
Additional context
Same pattern as #119767 (found by: lexical, vector, fix_path; vector: cosine distance 0.21 (agrees with the lexical leg)), #120647 (found by: vector; vector: cosine distance 0.20), #116407 (found by: lexical, vector, fix_path; vector: cosine distance 0.21 (agrees with the lexical leg)).
Open risks:
- A fix must keep
INbit-exact:f IN (0.0)matches only+0.0with and without the index today.
Found during automated review of PR #117722; the bug predates that PR (it reproduces on the master build just before it merged), so the introducing change is not identified yet. Severity P2 · Finding h_pr117722_002
Version info
- Resolved by: Look up both signed zeros in a bloom_filter index #123834
- Merged into:
26.10.1.1757-master(included in26.10and later)
Activity
Look up both signed zeros in a `bloom_filter` index
Algunenano commentedon Oct 13, 2026
Reverted in #125652