Skip to content

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

Description

@clickgapai

Describe what's wrong

  • Rows are silently dropped when filtering a float column equal to zero with a bloom_filter index.
  • Trigger is f = 0, f = -0.0, has, hasAny, or mapContainsKey over Float64/Array(Float64)/Map(Float64, String).
  • -0.0 and 0.0 compare equal, so both should match, but only the granule matching the exact bit pattern is kept.
  • IN is unaffected since it compares bit-exact values; disabling use_skip_indexes returns 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.

  • traverseTreeEquals hashes the converted constant the same way for scalar equals (MergeTreeIndexBloomFilter.cpp:1132), has(const, col) (:1073), has(col, const) (:1059), hasAny/hasAll (:1090), mapContains* (:1205), m[k] = v (:1271).
  • Only the arrayJoin paths decline floats, via bloomFilterHashDomainMatches (:591-601), whose comment names this exact reason.

Affected locations:

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.

▶ Run on ClickHouse Fiddle

-- 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 IN bit-exact: f IN (0.0) matches only +0.0 with 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

Activity

  1. added
    comp-skip-index
    on Oct 3, 2026
  2. Algunenano commented on Oct 13, 2026

    @Algunenano
    Member

    Reverted in #125652

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai_p2comp-skip-index

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions