Skip to content

Use explicit flag for secondary on cluster queries - #104881

Merged
tavplubix merged 2 commits into
masterfrom
explicit-secondary-on-cluster
May 20, 2026
Merged

tavplubix merged 2 commits into
masterfrom
explicit-secondary-on-cluster

Conversation

@tavplubix

@tavplubix tavplubix commented May 13, 2026 •

Copy link
Copy Markdown
Member

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):

Use an explicit flag in Context for secondary DDL/ON CLUSTER queries instead of SECONDARY_QUERY

Version info

  • Merged into: 26.5.1.894 (included in 26.5 and later)
  • Backported to: 26.5.1.880, 26.4.4.7, 26.3.12.2, 25.8.29.2

@clickhouse-gh

clickhouse-gh Bot commented May 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [8dcad2d]

Summary: ✅


AI Review

Summary

This PR replaces ON CLUSTER / replicated DDL detection based on ClientInfo::QueryKind::SECONDARY_QUERY with an explicit Context flag (isDDLOrOnClusterInternal). The security direction is correct, but one execution-semantic path still depends on SECONDARY_QUERY, so the patch currently introduces a behavior regression for some distributed DDL queries.

Findings

❌ Blockers

  • [src/Interpreters/DDLTask.cpp:294] setQueryKind(ClientInfo::QueryKind::SECONDARY_QUERY) was removed for DDL worker contexts, but worker-path dispatch in *Cluster table functions still keys off query_kind == SECONDARY_QUERY (for example src/TableFunctions/TableFunctionFileCluster.cpp:23, src/TableFunctions/TableFunctionURLCluster.cpp:13, src/TableFunctions/TableFunctionObjectStorageCluster.cpp:46). This violates the execution contract for CREATE ... ON CLUSTER ... AS SELECT ...: each DDL worker replica can fan out the cluster read again instead of taking a worker-local path, multiplying remote reads and potentially duplicating inserted data.
  • Suggested fix: either keep setQueryKind(ClientInfo::QueryKind::SECONDARY_QUERY) in DDL worker contexts (while using isDDLOrOnClusterInternal for trust-sensitive checks), or update those *Cluster worker checks to also treat isDDLOrOnClusterInternal as worker execution.
Tests

⚠️ Add a focused regression test for CREATE TABLE ... ON CLUSTER ... AS SELECT ... FROM fileCluster(...) (or urlCluster / objectStorageCluster) to prove DDL workers do not re-fan-out cluster table-function reads.

Final Verdict

Status: ⚠️ Request changes
Minimum required actions:

  1. Fix DDL worker-mode detection for *Cluster table functions as described above.
  2. Add one regression test covering ON CLUSTER DDL with a *Cluster table function.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 13, 2026
Comment thread src/Interpreters/DDLTask.cpp Resolved
@tavplubix
tavplubix marked this pull request as draft May 13, 2026 18:12
@tavplubix
tavplubix marked this pull request as ready for review May 15, 2026 11:43
Comment thread src/Interpreters/DDLTask.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 92.78% (90/97) | lost baseline coverage: 22 line(s) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! Very good change. Though there is no PoC. Could you please submit a test with PoC in a follow-up PR?

@alexey-milovidov alexey-milovidov self-assigned this May 17, 2026
@tavplubix
tavplubix enabled auto-merge May 20, 2026 15:16
@tavplubix
tavplubix added this pull request to the merge queue May 20, 2026
Merged via the queue into master with commit 3b542a9 May 20, 2026
167 checks passed
@tavplubix
tavplubix deleted the explicit-secondary-on-cluster branch May 20, 2026 15:39
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label May 20, 2026
@tavplubix tavplubix added pr-must-backport Pull request should be backported intentionally. Use this label with great care! v25.12-must-backport v26.2-must-backport v26.4-must-backport labels May 21, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 21, 2026
robot-clickhouse-ci-2 added a commit that referenced this pull request May 21, 2026
Cherry pick #104881 to 26.5: Use explicit flag for secondary on cluster queries
alexey-milovidov added a commit that referenced this pull request May 21, 2026
Backport #104881 to 26.5: Use explicit flag for secondary on cluster queries
robot-ch-test-poll2 added a commit that referenced this pull request May 21, 2026
Cherry pick #104881 to 26.3: Use explicit flag for secondary on cluster queries
robot-ch-test-poll2 added a commit that referenced this pull request May 21, 2026
Cherry pick #104881 to 26.4: Use explicit flag for secondary on cluster queries
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 21, 2026
tavplubix added a commit that referenced this pull request May 22, 2026
Backport #104881 to 26.4: Use explicit flag for secondary on cluster queries
tavplubix added a commit that referenced this pull request May 22, 2026
Backport #104881 to 26.3: Use explicit flag for secondary on cluster queries
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
…ry-on-cluster

Use explicit flag for secondary on cluster queries
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Jun 15, 2026
Backport of ClickHouse#104881 to 25.8: Use explicit flag for secondary on cluster queries
@tavplubix tavplubix removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 3, 2026
robot-ch-test-poll added a commit that referenced this pull request Jul 3, 2026
Cherry pick #104881 to 25.8: Use explicit flag for secondary on cluster queries
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 3, 2026
tavplubix added a commit that referenced this pull request Jul 6, 2026
Backport #104881 to 25.8: Use explicit flag for secondary on cluster queries
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Jul 24, 2026
Antalya 25.8, backport of ClickHouse#104881: Use explicit flag for secondary on cluster queries
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…4881

Backport ClickHouse#104881 to 26.4: Use explicit flag for secondary on cluster queries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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 v25.12-must-backport v26.2-must-backport v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants