Repository navigation
Conversation
|
It's a great idea! It will help when DISTINCT has a high cardinality to use a lot of memory. It will be slower otherwise. |
|
Dear @UnamedRus, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Good idea, what are the results? |
|
Workflow [PR], commit [9e225f8] Summary: ❌
|
|
|
I do think, that results (time & memory) are quite nice, but not nice enough for enabling it by default. Few problems:
|
|
Dear @UnamedRus, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
We can create the bloom filter and switch to this method only when the hash table grows to a certain size. |
|
It's already like that:
Logic as following: For final Distinct step Anyway, there is true parallel distinct implementation, which either make "cheap" copies of chunk, or use Scatter Transform to do final step in parallel. I tried to play with something like that, but found it hard to deal with optimizations which reorder Transforms. If it(Parallel) will be done, it may also mostly cover use case of BF pass Distinct + threadpool as well. May be, there is still some place for BF pass Distinct + treadpool (when we are not sure that true parallel Distinct is beneficial), as it can be switched on/off dynamically, and doesn't need to change pipeline. |
… bloom filter With `number % 10 > 0` about 90% of the rows are new, which is the threshold at which preliminary `DISTINCT` abandons deduplication, so the query measured the abandoning path rather than the bloom filter. With `number % 5 > 0` about 80% of the rows are new: below the abandoning threshold and above `distinct_pass_ratio_threshold_for_disabling_bloom_filter`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er and parallel `DISTINCT` paths The mask of rows that are known duplicates by their `LowCardinality` dictionary index was only applied by `buildSetFilter`. Once `checkSetFilter` (`check_only`), `buildCombinedFilter` (bloom filter) or `buildSetParallelFilter` (`hashed_two_level`) took over, every row was hashed and probed again. Pass the mask through these paths too and skip the masked rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts with the spilling of the preliminary `DistinctTransform` (`ISpillable`): `allow_spilling_` goes right after `max_bytes_before_pass_through_` in the constructor, and `spill` and `getMemoryStats` now also release and account the own set (hash set, bloom filter and `LowCardinality` filter) of the bloom-filter preliminary path. The interpreters use `getEffectiveMaxThreads` from master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n version 21 `QueryPlanSerializationSettings::readBinary` rejects unknown names, so a pre-26.11 peer failed to read a plan with a non-default bloom-filter setting of `DISTINCT`. Bump `DBMS_QUERY_PLAN_SERIALIZATION_VERSION` to 21 for release 26.11 and write `distinct_set_limit_for_enabling_bloom_filter`, `distinct_bloom_filter_bytes`, `distinct_pass_ratio_threshold_for_disabling_bloom_filter` and `distinct_bloom_filter_max_ratio_of_set_bits` only to peers at `DBMS_MIN_QUERY_PLAN_SERIALIZATION_VERSION_WITH_DISTINCT_BLOOM_FILTER` or above. An older peer runs its exact `DISTINCT` without the bloom filter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reconcile the bloom-filter `DISTINCT` with master's parallel `DISTINCT` (ClickHouse#114550): - `DistinctTransform` takes master's `shared_set_bytes_` and `coalesce_rows_` before the bloom-filter parameters. - The own-set path (bloom filter, parallel probing) is not used when the set memory is accounted globally across disjoint streams (`shared_set_bytes_`), because it does not report to `DistinctSetMemoryTracker`. - Coalescing flushes when the own set is released, not merely when `distinct_set` is absent (which it always is on the own-set path). - The thread budget of the final `DISTINCT` is shared among all its streams, including streams created by the scattered parallel `DISTINCT`. - Plan serialization version 21 now covers both `min_bytes_before_external_group_by` and the bloom-filter settings.
The `settings_changes_history` style check requires new settings to have a record under the current version, which is now 26.11. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=77728&sha=47e07f9ca6e3de70fff9628aca2226b79a259c2f&name_0=PR&name_1=Style%20check Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged current Conflict resolution / reconciliation with parallel
CI: fixed the Verified locally: |
# Conflicts: # src/Core/ProtocolDefines.h
`bucket_offsets` was declared after the `ThreadPoolCallbackRunnerLocal` in `buildSetParallelFilter`, so if scheduling threw during the second phase the vector was destroyed before the runner's destructor waited for the workers that read it. Declare it before the runner, and reserve the runner's tracking capacity so that a scheduled task can never be left untracked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…_filter_limit` The CI config sets `max_rows_in_distinct`, which disables the bloom filter and `check_only` modes, so the test did not exercise the code it protects. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=77728&sha=151c5ce6842f8e72205497789b64f7cf723e8692&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%204%2F6%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The |
|
The fix is in progress: #128236 (CI green, awaiting review). On job 123803207537 the report and uploads ended at 01:44:11, 113 minutes into the 7200 s timer. The 404 itself came from the dashboard outage during the CIDB switch (2026-10-29 09:04Z to 2026-10-30). |
# Conflicts: # src/Core/ProtocolDefines.h
…-budget estimate Building the hash-method state in `buildSetFilter`, `buildCombinedFilter` or `checkSetFilter` allocates `prepared_keys`, which can exceed the size of the input columns (a `Nullable(UInt64)` key takes about 9 bytes per row but is packed into a 16-byte key). Mirror `DistinctSetFilter::estimateFilteringMemory`: take the maximum of the column bytes and `estimatePreparedKeysMemory`, then add the masks. Add a test that runs the bloom-filter preliminary `DISTINCT` on a packed `Nullable(UInt64)` key with a small `max_bytes_before_external_distinct`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… insertion The existing tests never exceed `PARALLEL_DISTINCT_THRESHOLD`. The new test uses complex keys (`hashed_two_level`), 1500000 retained keys, 65536-row blocks, `max_threads = 4`, a single merged final stream (`allow_parallel_distinct = 0`) and no external spilling, with duplicates across blocks, and checks the exact result. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged current
|
…x the style check Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts: `addDistinctStep` moved from `Planner.cpp` to `PlannerSteps.cpp` on master, so the bloom-filter settings are passed there now; `DistinctStep::deserialize` keeps master's serialized `limit_hint` together with the bloom-filter settings; getters got `[[nodiscard]]` as on master. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review: `buildSetFilter`, `buildCombinedFilter`, `checkSetFilter` and
`buildSetParallelFilter` construct `Method::State` without `skips_rows`. For a
method with `prepare_keys` (`SetMethodHashed`), requesting a key hashes the
following 8-256 rows ahead, including rows masked out by the `LowCardinality`
dictionary-index filter, so the single-column `LowCardinality` fast path is lost.
Pass `{.skips_rows = mask != nullptr}` as `buildDistinctFilter` already does.
This is the likely cause of the `distinct_low_cardinality_prelimit_distinct_in_order`
regression in the performance comparison:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=77728&sha=latest&name_0=PR&name_1=Performance%20Comparison%20(arm_release%2C%20master_head%2C%201%2F6)
ClickHouse#77728
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict in `src/Processors/QueryPlan/DistinctStep.h`: master added the `external_distinct_disabled` member next to this PR's bloom-filter members. Both are kept. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The 26.11 release branch has been cut and `master` is now 26.12, so the four `distinct_*bloom_filter*` settings first appear in 26.12. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
🕵 Merged current
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
DISTINCTcan use less memory and run faster on high-cardinality queries by probing a bloom filter before the hash set, and the finalDISTINCTstep can use a two-level hash set and several threads.Workflow [PR]
Sync PR [sync-upstream/pr/77728]