Skip to content

Allow ATTACH PARTITION across explicit and implicit primary keys - #108590

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
jordiori:fix-primary-key-attach-partition
Jul 1, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
jordiori:fix-primary-key-attach-partition

Conversation

@jordiori

@jordiori jordiori commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #68948

Fix ATTACH PARTITION ... FROM and other PARTITION operations when one of the tables declares the PRIMARY KEY explicitly and the other inherits it implicitly from the ORDER BY and both tables have the same effective primary key.

Until now, this was failing with "Tables have different primary key".

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix ATTACH PARTITION ... FROM rejecting tables whose primary keys are equivalent but declared differently (one explicit PRIMARY KEY, the other implicit from ORDER BY).

Version info

  • Merged into: 26.7.1.331 (included in 26.7 and later)

@CLAassistant

CLAassistant commented Jun 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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.

Looks good, thank you!

@alexey-milovidov alexey-milovidov self-assigned this Jun 30, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a5997d0]

Summary: ✅


AI Review

Summary

This PR changes MergeTree partition source/destination structure validation to compare the effective primary-key expression list instead of the user-declared PRIMARY KEY AST, so equivalent explicit and implicit primary keys are accepted while real prefix mismatches remain rejected. I found no actionable correctness, safety, or metadata issues; the added stateless test covers both transfer directions for the accepted case and verifies the mismatch is still rejected.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 6/6 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 16 line(s) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 1, 2026
Merged via the queue into ClickHouse:master with commit 2b2b2eb Jul 1, 2026
167 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 1, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…tach-partition

Allow ATTACH PARTITION across explicit and implicit primary keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default 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.

Primary key error when doing alter table replace partition

4 participants