Skip to content

Add test for Distributed table inside Merge with distributed_group_by_no_merge=1 - #102112

Merged
alexey-milovidov merged 9 commits into
masterfrom
fix-distributed-group-by-no-merge-in-merge-table
Apr 26, 2026
Merged

alexey-milovidov merged 9 commits into
masterfrom
fix-distributed-group-by-no-merge-in-merge-table

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Apr 8, 2026 •

Copy link
Copy Markdown
Member

This PR adds an additional test for issue #75604 (Merge table wrapping a Distributed table with distributed_group_by_no_merge=1). The source-code fix was merged separately in #100859; the existing test there (04064_merge_distributed_group_by_no_merge.sql) covers a simple Merge over Distributed + Memory. This PR adds the more complex scenario from the original issue: a GLOBAL ANY INNER JOIN between the Merge-over-Distributed table and another Distributed table, with a GLOBAL IN subquery.

Originally this PR also contained the source-code fix (removing an overly strict assertion in StorageDistributed::getQueryProcessingStage); after rebasing on master that change is no longer in the diff because #100859 applied an equivalent fix.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99935&sha=1744b5eab84a5f177462c30caa27abc25746e98c&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

…rge=1` is inside a Merge table

When a `StorageMerge` with multiple source tables contains a `Distributed` table
and `distributed_group_by_no_merge=1` is set, `StorageMerge::getQueryProcessingStage`
returns `WithMergeableState` (min of source stages for multiple tables). Later,
`ReadFromMerge::createPlanForTable` passes this as `to_stage` to the Distributed
table's `getQueryProcessingStage`, which asserted `to_stage == Complete`.

The assertion was overly strict. The `distributed_group_by_no_merge=2` code path
already returns its stage without checking `to_stage`, and callers handle the mismatch.
Remove the assertion and let the caller decide the actual processing stage.

Fixes: #75604
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=99935&sha=1744b5eab84a5f177462c30caa27abc25746e98c&name_0=PR&name_1=BuzzHouse%20%28amd_tsan%29

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

clickhouse-gh Bot commented Apr 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8e53c54]

Summary: ✅


AI Review

Summary

This PR adds a new stateless regression test for the Merge-over-Distributed + GLOBAL ... JOIN scenario with distributed_group_by_no_merge=1 (issue #75604). I did not find correctness, safety, or performance issues in the change, and the scope is appropriately limited to tests.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 8, 2026
@alexey-milovidov
alexey-milovidov marked this pull request as draft April 8, 2026 17:25
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Why returning Complete from getQueryProcessingStage is correct even when the Merge table needs FetchColumns

The getQueryProcessingStage return value (storage_stage) is only used for the comparison in createPlanForTable at StorageMerge.cpp:1273. The actual stage passed to storage->read at line 1288 is processed_stage (= FetchColumns), not storage_stage:

auto storage_stage = storage->getQueryProcessingStage(...);  // Complete
if (processed_stage <= storage_stage && ...)                  // FetchColumns <= Complete → true
{
    storage->read(plan, ..., processed_stage, ...);           // reads at FetchColumns
}

So:

  • storage_stage = Complete (what Distributed says it can do)
  • processed_stage = FetchColumns (what Merge needs, because of JOIN)
  • FetchColumns <= Complete → true → enters the direct-read branch
  • Calls storage->read(..., processed_stage=FetchColumns, ...) → Distributed reads at FetchColumns

StorageDistributed::read passes processed_stage directly to the cluster proxy (StorageDistributed.cpp:1018,1026), so the remote shards process to FetchColumns and return raw columns. The distributed_group_by_no_merge setting only affects what getQueryProcessingStage reports, it doesn't change how read works when called with a specific stage.

The getQueryProcessingStage return value here means "I can process up to Complete" — it doesn't force reading at that stage. The caller decides the actual stage. This is the same pattern as distributed_group_by_no_merge=2, which returns WithMergeableStateAfterAggregation regardless of to_stage.

@nikitamikhaylov

nikitamikhaylov commented Apr 8, 2026 •

Copy link
Copy Markdown
Member

There is already a PR from Groene AI, can you please review it? #100859

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Thanks, unassigned @azat from it - there was no reaction for two weeks.

@alexey-milovidov
alexey-milovidov marked this pull request as ready for review April 8, 2026 17:35
@alexey-milovidov

Copy link
Copy Markdown
Member Author

The Fast test (arm_darwin) failure is unrelated to this PR — the fix is in #102184.

@@ -0,0 +1,29 @@
-- https://github.com/ClickHouse/ClickHouse/issues/75604

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 PR appears test-only (tests/queries/... changed). For test-only changes, Changelog category should be Not for changelog (or Build/Testing/Packaging Improvement), and a Changelog entry is not required. Please update the PR template fields to match the actual diff.

@alexey-milovidov alexey-milovidov changed the title Fix exception when Distributed table with distributed_group_by_no_merge=1 is inside a Merge table Add test for Distributed table inside Merge with distributed_group_by_no_merge=1 Apr 25, 2026
@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog and removed pr-bugfix Pull request with bugfix, not backported by default labels Apr 25, 2026
@alexey-milovidov alexey-milovidov self-assigned this Apr 26, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Apr 26, 2026
Merged via the queue into master with commit 07c2620 Apr 26, 2026
165 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-distributed-group-by-no-merge-in-merge-table branch April 26, 2026 11:14
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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