Skip to content

Distributed query plan: deserialize exchange data on every stream of the receive - #119236

Merged
davenger merged 23 commits into
masterfrom
exchange-parallel-serialization-deserialization
Sep 16, 2026
Merged

davenger merged 23 commits into
masterfrom
exchange-parallel-serialization-deserialization

Conversation

@davenger

@davenger davenger commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

When a distributed query plan receives data from other nodes, each sender has one exchange source, and that source decompressed and deserialized the sender's whole stream on one thread. With few senders this becomes the bottleneck of the receiving task: a task fed by 3 senders deserializes on 3 threads no matter how many cores it has, and the senders wait on it.

Now the source only receives the packets and hands them on as they are, and a deserializing transform turns the packets back into data. For the shuffle and the broadcast the packets are spread over max_threads streams first, so the deserialization and the steps after it run on all threads of the task. The gather keeps one stream per source, with the deserializer behind it: a sorted gather merges its streams in order, and the merge of partial aggregation results needs the buckets of every sender on one input, in order. The initiator reads the final result the same way, on one stream, so an ORDER BY result arrives in order. The bytes on the wire are unchanged. In-memory and file-based exchanges keep working with plain chunks.

The receiving side of the change in #119067; the diff includes that pull request until it is merged.

Related: #119067

Changelog category (leave one):

  • Experimental Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Distributed query plans (make_distributed_plan) now deserialize the data received through shuffle and broadcast exchanges on all threads of the receiving task instead of one thread per sender. Gather exchanges keep one stream per sender, so ordered results and merged aggregation states stay in order. This removes a bottleneck when a query runs on a small number of workers.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/119236]

The source of an exchange stream hands its packets on as one-row `String` chunks, and a deserializing transform behind a resize to `max_threads` turns them into data on every stream. Before, each source deserialized its sender's whole stream alone.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8478cee]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR moves streaming-exchange deserialization out of StreamingExchangeSource into per-stream receive transforms, and the current branch does fix the earlier protocol-correctness issues around end-of-stream markers and columnless streams. I am still at request changes because the remaining receive-side evidence only proves that extra StreamingExchangeDeserializingTransform processors exist, not that rows are actually deserialized on more than one stream or that the claimed few-sender bottleneck is gone.

Tests
  • ⚠️ [tests/queries/0_stateless/05176_distributed_plan_exchange_layout.sql:94] The processors_profile_log assertions stop at deserializers >= sources / deserializers > sources, so they still pass if one source/deserializer pair does all row work while the extra deserializers stay idle. Because the PR contract is receiver-side scaling on a few-sender task, please add focused evidence that at least two deserializers actually consume rows, or a small benchmark that shows the 3-sender bottleneck is gone.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: add focused evidence that receiver-side row work is actually spread across multiple deserializers, not just that the extra processors exist.

LLVM Coverage Report

Measured on commit 8478cee.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.50% 80.50% +0.00%

Changed lines: Changed C/C++ lines covered: 420/435 (96.55%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Sep 10, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). label Sep 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 8478ceef3191a740484f188c4f5b156e3315ea1f with master failed: RuntimeError: CI logs cluster query failed: SELECT check_start_time, instance_id FROM binar….

See the job log for details.

davenger and others added 2 commits September 10, 2026 21:16
The merge of partial aggregation results behind a gather expects every sender's buckets on one input stream, in order. Spreading the received packets over `max_threads` streams made `GroupingAggregatedTransform` see a bucket twice.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
A real server, sink and source in all four serialize/deserialize pairings, the sender stalling at its pending cap, and a source facing malformed packets from a fake peer.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

The one flagged query (ClickBench Q16, +10.1%, median 557 -> 613.5 ms) was already suppressed deterministically as within master's current variance band, and that call holds up: the query has a noisy history, and this PR only reworks the distributed-query exchange receive path (new receiveExchangeStreams helper, per-stream deserializer transforms, end-of-stream packet handling) plus Docker version bumps and backport changelogs. A single-node ClickBench SELECT does not run any of that code, so the small consistent delta is run-to-run variance, not a PR effect. No regression is attributable to this change.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 16 not_sure 557 614 +10.1% <0.0001 cpu: Q16's +10.1% sits inside master's current variance band on an intrinsically noisy query; this PR only touches distributed-exchange receive plumbing that a single-node ClickBench SELECT never exercises, so the delta is run-to-run variance.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: ed6e733a-cf1d-490c-a216-08f99f19d5b8
  • MIRAI run: c8d6d80e-78c4-44aa-9c25-c7646eeb0079
  • PR check IDs:
    • clickbench_342052_1789501463
    • clickbench_342058_1789501463
    • clickbench_342064_1789501463
    • tpch_adapted_1_official_342075_1789501463
    • tpch_adapted_1_official_342087_1789501463
    • tpch_adapted_1_official_342122_1789501464

davenger and others added 6 commits September 11, 2026 11:51
A real server, sink and source in all four serialize/deserialize pairings, the sender stalling at its pending cap, and a source facing malformed packets from a fake peer.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
(cherry picked from commit c0247ec)
…rialization-deserialization

# Conflicts:
#	src/Server/DistributedQuery/tests/gtest_streaming_exchange_transport.cpp
…rialization-deserialization

# Conflicts:
#	src/Server/DistributedQuery/StreamingExchangeProtocol.cpp
#	src/Server/DistributedQuery/StreamingExchangeSource.cpp
#	src/Server/DistributedQuery/tests/gtest_streaming_exchange_transport.cpp
…rialization-deserialization

# Conflicts:
#	src/Processors/QueryPlan/tests/gtest_shuffle_exchange_parallelism.cpp
…rialization-deserialization

# Conflicts:
#	src/Processors/QueryPlan/tests/gtest_shuffle_exchange_parallelism.cpp
Comment thread src/Processors/QueryPlan/QueryPlan.cpp Resolved
davenger and others added 5 commits September 11, 2026 18:43
…rialization-deserialization

# Conflicts:
#	tests/queries/0_stateless/05176_distributed_plan_exchange_layout.reference
#	tests/queries/0_stateless/05176_distributed_plan_exchange_layout.sql
UNION ALL SELECT 3, 'scatter: serializers = scatters * sinks', min(serializers = scatters * sinks) FROM v_exchange_layout WHERE scatters > 0
UNION ALL SELECT 4, 'scatter: max rows into one serializer <= max rows into one scatter', min(max_rows_into_serializer <= max_rows_into_scatter) FROM v_exchange_layout WHERE scatters > 0
UNION ALL SELECT 5, 'broadcast: serializers = read streams and serialized rows = read rows', min(serializers = reads AND rows_serialized = rows_read) FROM v_exchange_layout WHERE sinks > 1 AND scatters = 0
UNION ALL SELECT 6, 'receive: deserializers >= sources in every task', min(deserializers >= sources) FROM v_exchange_layout WHERE sources > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These receive-side checks only prove that extra StreamingExchangeDeserializingTransform processors exist. They still pass if receiveExchangeStreams/resize(max_threads) instantiates idle deserializers while one source/deserializer pair keeps doing all of the row work, because nothing here checks input_rows on the deserializers or any before/after runtime.

The PR contract is receiver-side scaling on a few-sender / many-core task, so please add focused evidence that rows actually flow through more than one deserializer (or a small benchmark on that shape showing the old bottleneck is gone).

@CheSema CheSema self-assigned this Sep 14, 2026
@davenger
davenger added this pull request to the merge queue Sep 16, 2026
Merged via the queue into master with commit 9d77a10 Sep 16, 2026
348 of 351 checks passed
@davenger
davenger deleted the exchange-parallel-serialization-deserialization branch September 16, 2026 03:24
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... and removed comp-distributed Distributed table engine & query routing across shards (sharding/load balancing). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... pr-experimental Experimental Feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants