Repository navigation
[draft] parallel distinct in order - #48988
devcrafter wants to merge 3 commits into
Conversation
|
This is an automated comment for commit 742995e with description of existing statuses. It's updated for the latest CI running
|
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
12 similar comments
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Dear @devcrafter, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message. |
|
Closing this draft: the motivation is still valid, but nothing here can be revived. The problem is unchanged - the final The patch itself no longer applies in any part: Two things have landed since that make a fresh attempt cheaper: |
The final `DISTINCT` merged all of its input streams into one and deduplicated
them on a single thread, so `SELECT DISTINCT` did not scale with `max_threads`
while the equivalent `GROUP BY` did - aggregation parallelizes its merge over
two-level hash tables, `DISTINCT` had nothing of the sort.
Repartition the input streams by the hash of the `DISTINCT` columns instead of
merging them: equal values then land in the same stream, so every stream can be
deduplicated on its own, and what is left to merge is already deduplicated. The
repartitioning uses `scatterByPartition`, which `SortingStep` and
`ShuffleSendStep` already use.
The new setting `allow_parallel_distinct`, on by default, controls it. Whether
the order of the step's output is free is only known where the sorting
properties are, so the decision is taken in `applyOrder`. It is not applied
when the input is globally sorted, when `max_rows_in_distinct` or
`max_bytes_in_distinct` is set, when there is a `LIMIT`, or when the streams
are already disjoint - `allow_distinct_partitions_independently` covers that
case and skips the merge entirely.
Every input chunk is split across all partitions, so the number of partitions
is capped rather than following `max_threads`: on `SELECT DISTINCT number FROM
numbers_mt(4e7)` the total CPU time the scatter adds grows by 8% at 4
partitions, 20% at 16 and 96% at 96.
Wall clock, minimum of 3 runs, aarch64:
workload threads before after speedup
20M distinct UInt64 4 0.442 s 0.205 s 2.16x
(MergeTree) 16 0.458 s 0.148 s 3.09x
96 0.502 s 0.165 s 3.04x
40M distinct UInt64 4 0.965 s 0.545 s 1.77x
(numbers_mt) 16 0.929 s 0.360 s 2.58x
96 0.886 s 0.299 s 2.96x
8M distinct String 4 0.515 s 0.288 s 1.79x
(numbers_mt) 16 0.517 s 0.093 s 5.56x
96 0.518 s 0.083 s 6.24x
`DISTINCT` without `ORDER BY` has no defined row order, and the repartitioning
changes the order it happens to produce. Two tests relied on it:
`04109_sort_propagation_apply_order` asserts that per-stream sortedness reaches
`DISTINCT`, so it pins the setting off, and
`00585_union_all_subquery_aggregation_column_removal` gets the explicit
`ORDER BY` it was missing.
Closes: ClickHouse#114532
Related: ClickHouse#48988
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Avoid the final single-threaded distinct step by reading in sorted non-intersecting ranges from MergeTree storage