Repository navigation
Look up both signed zeros in a bloom_filter index - #123834
Conversation
`-0.0 = 0.0`, but a `bloom_filter` index holds the hash of each value's bits, which differ for the two zeros, so `f = 0` skipped the granules holding `-0.0`. The same happened for `has` in both directions, `hasAny`, `hasAll`, `mapContainsKey` and `m[k] = v`. For a float zero, the lookup now also includes the hash of the other zero. These predicates match a granule that may hold any of their hashes, so the index format does not change and existing parts work. `hasAll` needs every hash, so it does not use the index when the array has a zero. `IN` compares bits and is unchanged. Closes: ClickHouse#123744
|
Workflow [PR], commit [728c0ca] Summary: ✅
AI ReviewSummaryThis PR fixes the Final Verdict
LLVM Coverage ReportMeasured on commit 728c0ca.
Changed lines: Changed C/C++ lines covered: 59/62 (95.16%) · Uncovered code |
There was a problem hiding this comment.
On a master build with mv Map(String, Float64), a mapValues(mv) index and the row map('a', -0.0) mapContainsValue(mv, 0.0) returns [] with the index and [1] without.
This branch now uses hashWithFieldAndOtherZero, so the PR fixes it.
I will approve, but please add the m[k] IN and mapContainsValue queries and mention mapContainsValue in the changelog entry.
| ColumnPtr hashes = hashWithColumnAndOtherZeros(actual_type, column, has_float_zero); | ||
|
|
||
| /// `hasAll` needs one of the two zeros in the granule, while `FUNCTION_HAS_ALL` needs every hash. | ||
| if (function_name == "hasAll" && has_float_zero) |
There was a problem hiding this comment.
I have a performance suggestion, because hasAll with a zero element could keep pruning instead of dropping the index.
- mayBeTrueOnGranule
ANDs the entries inout.predicate, and each entry is checked with any-of underFUNCTION_HAS_ANY. That is exactly the semantics needed byhasAll`. - Emit
FUNCTION_HAS_ANYwith one predicate entry per element:- a non-zero element gets its single hash;
- a zero element gets both zero hashes.
- hasAll(a, [0.0, 42.0]) would then still skip granules without 42. Today it reads every granule.
Fine as a follow-up ;)
There was a problem hiding this comment.
Done in the draft #124045: one FUNCTION_HAS_ANY entry per element, with both hashes for a zero. hasAll(a, [0.0, 42.0]) now selects 2 of 103 granules, where before it read all of them. It stays a draft until this PR is merged.
| return false; | ||
|
|
||
| out.predicate.emplace_back(std::make_pair(position, BloomFilterHash::hashWithField(actual_type.get(), converted_field))); | ||
| out.predicate.emplace_back(std::make_pair(position, hashWithFieldAndOtherZero(actual_type, converted_field))); |
There was a problem hiding this comment.
IIUC this fix also covers mapContainsValue, but the description, changelog and test leave it out.
There was a problem hiding this comment.
Done in 728c0ca: mapContainsValue(mv, 0.0) over a mapValues index, and m[0.0] IN ('x') over a mapKeys index, are now in 05325_bloom_filter_signed_zero. On master both return [3] with the index and [1,3] without it. I also mentioned mapContainsValue in the description and the changelog. The hasAll pruning and the float arrayJoin paths are in the draft follow-up #124045.
|
The With this change there is a remedy for the float exclusion in What if we do it as a folloup PR? |
…ter` Address review: add the `mapContainsValue` query over a `mapValues` index and `m[0.0] IN (...)` over a `mapKeys` index. Both missed the row with `-0.0` on master with the index and are fixed by this PR. `mv['a'] IN (0.0)` stays bit-exact. The queries that use `m[0.0]` pin `optimize_functions_to_subcolumns = 1`: with 0, `m[0.0]` on a `Map(Float64, String)` throws `ILLEGAL_TYPE_OF_ARGUMENT` even without an index, which the randomized settings hit.
Raised a follow-up PR covering the remaining aspects: #124045 |
|
@Ergus I addressed the review in 728c0ca. I added the |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
|
@Ergus Gentle nudge on the PR : ) |
Ergus
left a comment
There was a problem hiding this comment.
LGTM.
Just made two final totally optional comments. Please confirm if you like to address them or keep this as is and I will merge then.
| if (!isFloat(removeLowCardinalityAndNullable(type))) | ||
| return hashes; | ||
|
|
||
| MutableColumnPtr result; |
There was a problem hiding this comment.
I think that this is ok to merge.
Just a suggestion:
The loop appends the other-zero hash once per zero element.
hasAny(a, [0.0, 0.0, 0.0]) appends three identical hashes, and every granule check iterates all of them in maybeTrueOnBloomFilter.
If the array already holds both 0.0 and -0.0, no extra hash is needed, but the loop still appends two. Track the signs seen instead and append at most one hash per missing sign after the loop:
WHat about something like (untested)
bool has_positive = false;
bool has_negative = false;
for (size_t i = 0; i < column->size(); ++i)
{
Field value = (*column)[i];
if (!isFloatZero(type, value))
continue;
(std::signbit(value.safeGet<Float64>()) ? has_negative : has_positive) = true;
}
has_float_zero = has_positive || has_negative;
if (!has_float_zero || (has_positive && has_negative))
return hashes;
auto result = IColumn::mutate(std::move(hashes));
assert_cast<ColumnUInt64 &>(*result).insertValue(
BloomFilterHash::hashWithField(type.get(), has_positive ? Field(-0.0) : Field(0.0))->getUInt(0));
return result;|
|
||
| static Field otherFloatZero(const Field & zero) | ||
| { | ||
| return std::signbit(zero.safeGet<Float64>()) ? Field(0.0) : Field(-0.0); |
There was a problem hiding this comment.
Why not something simpler: Field(-zero.safeGet<Float64>()) ?
| /// hashes matches a granule that may hold any of them, except for `FUNCTION_HAS_ALL`. | ||
| static ColumnPtr hashWithFieldAndOtherZero(const DataTypePtr & type, const Field & field) | ||
| { | ||
| ColumnPtr hash = BloomFilterHash::hashWithField(type.get(), field); |
There was a problem hiding this comment.
Just a cosmetic observation:
I see that hashWithField allocates a ColumnConst over a one-row ColumnUInt64, and the helper does this twice only to read getUInt(0) from each.
An UInt64-returning variant in BloomFilterHash would avoid both allocations.
I would not add API surface for it unless the follow-up PR for hasAll also needs the raw hash (which it likely does) since it emits one predicate entry per element.
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]>
b7ce5f8
Conflict in `MergeTreeIndexBloomFilter.cpp`: master (#123834) added `hashWithFieldAndOtherZero` / `hashWithColumnAndOtherZeros` to probe the hash of the other signed zero. With this PR both zeros hash the same, and `hashWithField` / `addLegacyNegativeZeroProbes` already add the raw-bit hash of `-0.` for parts written by older versions, so master's helpers are replaced by this PR's mechanism (they would have dropped the legacy probe). `hasAll` with a zero drops the zero probes instead of disabling the index. Conflict in `ColumnsHashing.h`: keep both the negative zero canonicalization and the new `LowCardinality` cache initialization.
The test came from master (#123834) and pinned that `IN` compares the bits of floating point values. With this PR `-0. IN (0.)` is true, like `=`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
When randomized with |
…ash-keys Master reverted #123834 (`Look up both signed zeros in a bloom_filter index`) in #125652. This branch had already replaced its lookup of both zeros with the canonicalized hashes and the legacy probes of `BloomFilterHash`, so the conflicts in `MergeTreeIndexBloomFilter.cpp` are resolved in favor of this branch, and the test `05325_bloom_filter_signed_zero`, which covers this behavior, is kept.
With the randomized `map_serialization_version_for_zero_level_parts = 'with_buckets'`, `m[0.0]` on a `Map(Float64, String)` read only the bucket of the positive zero and missed the row with the key `-0.`, with and without the index. The bucket of a key is chosen by the raw bits of the value, which is a part of the format of a data part, so this is not about the `bloom_filter` index. This is why the test failed on master and #123834 was reverted: #123834 (comment) https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=40fc4717e5517a27aa1a01fb9c78ca91a2bb8c40&name_0=MasterCI&name_1=Stateless+tests+%28arm_binary%2C+ParallelReplicas%2C+s3+storage%2C+parallel%29 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Edited by the nightly changelog CI job following .claude/skills/edit-changelog/SKILL.md. Changelog-revert: 125458 125455 Revert "Revert "Iceberg variant type"" Changelog-revert: 125463 110114 Revert "Push filters below WindowStep on PARTITION BY columns" Changelog-revert: 125569 116724 Revert "Verify the server certificate hostname on outbound TLS connections" Changelog-revert: 125652 123834 Revert "Look up both signed zeros in a bloom_filter index" Changelog-deleted-entry: 116724 [Backward Incompatible Change] [section] * Outbound TLS connections now verify that the server certificate names the host that was connected to. This affects `clickhouse-client --secure`, `remoteSecure`, `Distributed` over the secure native protocol, secure `Keeper` connections, and HTTPS clients such as `s3`, `url`, HTTP dictionaries, and JWT token endpoints. Connecting to an endpoint whose certificate does not name it, for example an IP address with no matching SAN, an S3-compatible gateway fronted by a different name, or an internal CA with missing SANs, now fails with `Unacceptable certificate`. Set `openSSL.client.extendedVerification` to `false` to restore the previous behavior, or pass `--tls-sni-override` to name the host the certificate was issued for. Loopback addresses stay exempt unless `verificationMode` is `strict`, and the default for `openSSL.server.extendedVerification` is unchanged. [#116724](#116724) ([Groene AI](https://github.com/groeneai)). Changelog-deleted-entry: 123834 [Bug Fix (user-visible misbehavior in an official stable release)] [section] * Fixed a `bloom_filter` index on a float column skipping rows with the other signed zero, for example `-0.0` for `WHERE f = 0`. It affected `equals`, `has`, `hasAny`, `hasAll`, `mapContainsKey`, `mapContainsValue`, and map element comparisons, including `m[k] IN (...)`. [#123834](#123834) ([Ashish Kumar Choubey](https://github.com/aschoube)).
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
A bucketed `Map` puts a key into the bucket of the hash of its bits, and `m[k]` read only the bucket of `k`, so `m[0.0]` did not find a `-0.0` key in another bucket. A key with a float zero, also inside a `Tuple` or an `Array`, now reads the whole `Map`. This made `05325_bloom_filter_signed_zero` fail with `map_serialization_version_for_zero_level_parts = 'with_buckets'`: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=40fc4717e5517a27aa1a01fb9c78ca91a2bb8c40&name_0=MasterCI&name_1=Stateless+tests+%28arm_binary%2C+ParallelReplicas%2C+s3+storage%2C+parallel%29 Related: ClickHouse#123834
Closes: #123744
Related: #117722
A
bloom_filterindex on a float column skipped the granules holding the other signed zero:It also happens on 26.4.5.143, and for
Float32,hasin both directions,hasAny,hasAll,mapContainsKey,mapContainsValue,m[k] = vandm[k] IN (...).Cause
-0.0 = 0.0, but the index storesBloomFilterHashof each value's bits, and the bits of the two zeros differ.MergeTreeIndexConditionBloomFilter::traverseTreeEqualshashed the converted constant the same way, so a zero constant looked up only one of the two zeros.bloomFilterHashDomainMatchesalready excludes floats for this reason, but only on thearrayJoinpaths.Change
For a float zero constant, the lookup now also includes the hash of the other zero:
equals,has(array_column, x),mapContainsKey,mapContainsValueand the otherhasover aMap,m[k] = vandm[k] IN (...)usehashWithFieldAndOtherZero.has(constant_array, column)andhasAny/hasAllusehashWithColumnAndOtherZeros, which adds the other zero for each zero element.These predicates already match a granule that may hold any of their hashes (
maybeTrueOnBloomFilterwithmatch_all = false), so a zero now matches a granule with either zero. Nothing changes in what is written, so existing parts work as they are. Normalizing-0.0when hashing would not be enough, because existing parts already storehash(-0.0).hasAllneeds every hash in the granule, but for a zero element one of the two is enough, sohasAllwith a zero element does not use the index.INcompares bits (f IN (0.0)does not match-0.0, with or without the index), so it is not changed.The index still skips most granules for a zero, since it looks up two hashes instead of one. On 100 rows with
index_granularity = 1, the index selects 10 of 100 granules forf = 0with this PR (4 before, which missed-0.0), and 8 of 100 forf = 42both before and after.Test
05325_bloom_filter_signed_zerocompares every function above with and without the index, onFloat64,Float32,Array(Float64)andMap(Float64, String). It also coversmapContainsValueover amapValuesindex,m[0.0] IN (...)over amapKeysindex,INand a non-zero constant, and checks withforce_data_skipping_indicesandmax_rows_to_readthat the index still prunes for0and42. On an unfixed build the eleven zero queries miss rows. The queries withm[0.0]pinoptimize_functions_to_subcolumns = 1: with 0,m[0.0]on aMap(Float64, String)throwsILLEGAL_TYPE_OF_ARGUMENTeven without an index, which is unrelated to this change. With the fix all pass, also with--test-runs 5under randomized settings, apart from runs where the randomizer enabled parallel replicas: my local server does not define theparallel_replicascluster (CLUSTER_DOESNT_EXIST), which CI has.I ran the 62 existing stateless tests matching
bloomon servers started from both builds. No failure is caused by the change: the tests that failed only with the fix passed when rerun, or failed on the same missing cluster.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
bloom_filterindex on a float column skipping rows with the other signed zero, for example-0.0forWHERE f = 0. It affectedequals,has,hasAny,hasAll,mapContainsKey,mapContainsValueand map element comparisons, includingm[k] IN (...).Workflow [PR]
Sync PR [sync-upstream/pr/123834]
Version info
26.10.1.1757-master(included in26.10and later)