Skip to content

Direct join under parallel replicas + serialize_query_plan - #105260

Closed
devcrafter wants to merge 4 commits into
masterfrom
fix-pr-direct-join
Closed

devcrafter wants to merge 4 commits into
masterfrom
fix-pr-direct-join

Conversation

@devcrafter

@devcrafter devcrafter commented May 18, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Adds a regression test 04034_pr_direct_join that exercises the failing direct-join shape under parallel replicas + serialize_query_plan = 1. Until JoinStepLogicalLookup::serialize is implemented, the query is asserted to fail with NOT_IMPLEMENTED on the remote node.

Also threads is_merge_tree through ReadFromTableStep so the replica-side reconstruction can pick the right read path for direct joins, plus a small touch-up in PlannerJoinTree.cpp and ClusterProxy/executeQuery.cpp carrying the additional state.

Two commits:

  1. Reveal issue with direct join — adds is_merge_tree to ReadFromTableStep, threads it through serialization and the planner, plus the new regression test that documents the current limitation.
  2. Make 04034_pr_direct_join stable under random settings — tags the test so random-settings randomization doesn't change the plan shape underneath it.

devcrafter and others added 2 commits May 18, 2026 19:06
The test exercises a very specific configuration (parallel replicas +
`parallel_replicas_local_plan = 0` + `join_algorithm = direct` +
`serialize_query_plan = 1`) to assert that serialization of
`JoinStepLogicalLookup` raises `NOT_IMPLEMENTED`. Random settings in
the flaky check can change the plan so the lookup step is not reached
remotely, the query succeeds, and the test fails with "query succeeded
but server error '48' was expected".

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97261&sha=0537180f689f5e8f09d034af910c5b6800f9d739&name_0=PR&name_1=Stateless+tests+%28amd_asan_ubsan%2C+flaky+check%29
PR: #97261

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [74f8712]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
04034_pr_direct_join FAIL cidb
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED
Build (arm_asan_ubsan) DROPPED
Build (arm_tsan) DROPPED

AI Review

Summary

This PR threads is_merge_tree through ReadFromTableStep so direct-join planning can survive replica-side plan reconstruction, and it adds a regression test for the direct-join + parallel-replicas + serialize_query_plan path. The current patch still has a wire-compatibility break in query-plan serialization and the new test does not encode the failure contract it describes, so it is not ready to merge.

Findings

❌ Blockers

  • [src/Processors/QueryPlan/ReadFromTableStep.cpp:59] ReadFromTableStep::serialize repurposes flag bit 8 from use_parallel_replicas to is_merge_tree and moves use_parallel_replicas to bit 16 while query-plan serialization version stays 0. This changes the v0 wire contract and breaks mixed-version communication: old readers will try to consume a payload byte for bit 8 that new writers no longer emit, and new readers will skip the old payload when only bit 8 is set. Suggested fix: keep old bit semantics for version 0 and add is_merge_tree under a new serialization version (or equivalent backward-compatible encoding), with deserialize logic keyed by version.

⚠️ Majors

  • [tests/queries/0_stateless/04034_pr_direct_join.sql:48] The test text says we currently expect NOT_IMPLEMENTED until JoinStepLogicalLookup::serialize exists, but the SELECT has no expected-error annotation. That means the test contract does not match the stated behavior. Suggested fix: add -- { serverError NOT_IMPLEMENTED } to the statement that is expected to fail (or, if behavior is now expected to succeed, update the test comments and .reference output accordingly).
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Make ReadFromTableStep serialization backward compatible for version 0 (or bump/query-plan version and branch serialization/deserialization accordingly).
  2. Align 04034_pr_direct_join with its stated contract by encoding the expected NOT_IMPLEMENTED error (or by updating the test to assert successful output if that is now the intended behavior).

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 18, 2026
flags |= 4;
if (use_parallel_replicas)
if (is_merge_tree)
flags |= 8;

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.

This repurposes flag bit 8 from use_parallel_replicas to is_merge_tree and moves use_parallel_replicas to bit 16, while DBMS_QUERY_PLAN_SERIALIZATION_VERSION stays 0.

That changes the v0 wire contract for ReadFromTableStep: mixed-version nodes with serialize_query_plan = 1 will not agree on bit meanings and can deserialize the step incorrectly.

Please keep existing bit semantics for v0 (leave use_parallel_replicas on bit 8 and use a new bit for is_merge_tree), or bump/version-gate query-plan serialization.

@devcrafter
devcrafter marked this pull request as draft May 18, 2026 19:01
@devcrafter devcrafter changed the title Reveal issue with direct join under parallel replicas + serialize_query_plan Direct join under parallel replicas + serialize_query_plan May 18, 2026

SYSTEM ENABLE FAILPOINT parallel_replicas_wait_for_unused_replicas;

SELECT t0.Id, sum(sipHash64(t0.Payload)), count(), countIf(t1.Attribute != ''), sum(sipHash64(t1.Attribute)) AS attr_hash_sum

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.

The test body says this query should document the current NOT_IMPLEMENTED limitation (until JoinStepLogicalLookup::serialize exists), but this line has no expected-error annotation. In 0_stateless tests that means a NOT_IMPLEMENTED exception makes the test fail instead of pass.

Please add an explicit expectation on this query (for example -- { serverError NOT_IMPLEMENTED }) so the test actually validates the intended contract.

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.

This is still live in the current patch: the test body says we are documenting the current NOT_IMPLEMENTED limitation until JoinStepLogicalLookup::serialize exists, but this SELECT still has no expected-error annotation.

Without an explicit -- { serverError NOT_IMPLEMENTED } expectation on this statement, the test contract does not match the stated behavior.

devcrafter added a commit that referenced this pull request May 18, 2026
The direct-join regression test was extracted into PR #105260 along with
its `ReadFromTableStep::is_merge_tree` dependency. Drop it from this
branch; it'll come back via the merge from master once #105260 lands.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

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.

@abashkeev abashkeev added the comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). label Sep 4, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The direct-join regression test was extracted into PR ClickHouse#105260 along with
its `ReadFromTableStep::is_merge_tree` dependency. Drop it from this
branch; it'll come back via the merge from master once ClickHouse#105260 lands.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 2, 2026
…f_rows_per_replica`

- `03518_key_condition_binary_search` counts index search profile events. The extra plan
  that estimates the rows to read runs the index analysis again, so pin the setting to `0`.
- `02769_parallel_replicas_unavailable_shards` expects the unavailable replica to be picked.
  A positive value lowers the number of replicas for the 10-row table, so the counter stays `0`.
- `05452_pr_min_rows_estimate_direct_join_merge_tree` flakily failed in the `distributed plan`
  job: a remote replica that receives a serialized query plan cannot build a direct join yet
  (#105260). The test is about the plan built on
  the initiator, so it now sets `serialize_query_plan = 0`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=71028&sha=6494bace60a09a4c9e5697f5a0d03ed06a4e36d9&name_0=PR
PR: #71028

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

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.

@devcrafter

Copy link
Copy Markdown
Member Author

Not actualy anymore, serialized query plan is replaced by plan based parallel replicas development

@devcrafter devcrafter closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-parallel-replicas Parallel reading from replicas for query speed (not data replication consistency). pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants