Repository navigation
fix: reject sequence sources in table clone - #27118
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review passed on exact head f460f51 (base/merge-base bdbd613). The sequence relkind check runs before CREATE rewrite and physical clone for live and snapshot sources; existing base-table and view/external behavior is preserved. No new resource, wait, or growth paths. Fresh validation passed: diff check, focused regression, full pkg/sql/plan tests, and go list/build/vet; exact-head CI is green.
Merge Queue Status
This pull request spent 18 seconds in the queue, with no time running CI. ReasonThe pull request can't be updated
HintYou should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again. Tick the box to put this pull request back in the merge queue (same as
|
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27050 ## What this PR does / why we need it: ### Root cause `CREATE TABLE ... CLONE` resolves its source and then reuses the shared `buildCreateTable` LIKE/CLONE rewrite path. That path rejected views and external tables but allowed `catalog.SystemSequenceRel` to fall through. The bare CREATE TABLE rewrite therefore changed the source's internal seven-column sequence relation into an ordinary writable table, after which sequence functions rejected the target because it no longer had sequence relkind. ### Changes - Reject `SystemSequenceRel` with the existing `... is not BASE TABLE` validation before the CREATE TABLE rewrite and physical clone. - Add a planner unit test covering live CLONE, named-snapshot CLONE, and LIKE sources built from a resolved sequence definition. - Add distributed BVT coverage for live and named-snapshot sequence CLONE, LIKE, failure atomicity, source sequence progression, ordinary base-table CLONE, and view/external-table controls. ### Issue-to-test proof - The live sequence CLONE and LIKE statements now return `is not BASE TABLE`; both target table and column catalog counts remain zero, and the source remains `relkind = 'S'`. - The named-snapshot sequence CLONE returns the same error, leaves no target table or columns, and does not alter the source's next value. - The ordinary base-table CLONE still creates an `r` table with the original row. - View and external-table CLONE retain the same non-BASE-TABLE rejection and leave no targets. ### Tests run - `make thirdparties` - `make cgo` - `make build` - `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestBuildCreateTableLikeAndCloneRejectsSequenceSource$' ./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan` - `GOWORK=off go build -mod=readonly ./pkg/sql/plan` - `GOWORK=off go vet -mod=readonly ./pkg/sql/plan` - Distributed `clone_sequence` BVT: 34/34, 100% success; generated results were manually checked against the SQL semantics. ### Compatibility and residual risk The production change is one additional source-relkind check in the existing shared non-base-table guard. It does not alter sequence storage or the physical clone executor, and it preserves ordinary base-table, view, and external-table behavior. Supporting sequence duplication remains intentionally out of scope; sequence-specific cloning would require a separate operation that preserves `relkind = 'S'` and sequence invariants. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27050 ## What this PR does / why we need it: ### Root cause `CREATE TABLE ... CLONE` resolves its source and then reuses the shared `buildCreateTable` LIKE/CLONE rewrite path. That path rejected views and external tables but allowed `catalog.SystemSequenceRel` to fall through. The bare CREATE TABLE rewrite therefore changed the source's internal seven-column sequence relation into an ordinary writable table, after which sequence functions rejected the target because it no longer had sequence relkind. ### Changes - Reject `SystemSequenceRel` with the existing `... is not BASE TABLE` validation before the CREATE TABLE rewrite and physical clone. - Add a planner unit test covering live CLONE, named-snapshot CLONE, and LIKE sources built from a resolved sequence definition. - Add distributed BVT coverage for live and named-snapshot sequence CLONE, LIKE, failure atomicity, source sequence progression, ordinary base-table CLONE, and view/external-table controls. ### Issue-to-test proof - The live sequence CLONE and LIKE statements now return `is not BASE TABLE`; both target table and column catalog counts remain zero, and the source remains `relkind = 'S'`. - The named-snapshot sequence CLONE returns the same error, leaves no target table or columns, and does not alter the source's next value. - The ordinary base-table CLONE still creates an `r` table with the original row. - View and external-table CLONE retain the same non-BASE-TABLE rejection and leave no targets. ### Tests run - `make thirdparties` - `make cgo` - `make build` - `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestBuildCreateTableLikeAndCloneRejectsSequenceSource$' ./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan` - `GOWORK=off go build -mod=readonly ./pkg/sql/plan` - `GOWORK=off go vet -mod=readonly ./pkg/sql/plan` - Distributed `clone_sequence` BVT: 34/34, 100% success; generated results were manually checked against the SQL semantics. ### Compatibility and residual risk The production change is one additional source-relkind check in the existing shared non-base-table guard. It does not alter sequence storage or the physical clone executor, and it preserves ordinary base-table, view, and external-table behavior. Supporting sequence duplication remains intentionally out of scope; sequence-specific cloning would require a separate operation that preserves `relkind = 'S'` and sequence invariants. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#27050 ## What this PR does / why we need it: ### Root cause `CREATE TABLE ... CLONE` resolves its source and then reuses the shared `buildCreateTable` LIKE/CLONE rewrite path. That path rejected views and external tables but allowed `catalog.SystemSequenceRel` to fall through. The bare CREATE TABLE rewrite therefore changed the source's internal seven-column sequence relation into an ordinary writable table, after which sequence functions rejected the target because it no longer had sequence relkind. ### Changes - Reject `SystemSequenceRel` with the existing `... is not BASE TABLE` validation before the CREATE TABLE rewrite and physical clone. - Add a planner unit test covering live CLONE, named-snapshot CLONE, and LIKE sources built from a resolved sequence definition. - Add distributed BVT coverage for live and named-snapshot sequence CLONE, LIKE, failure atomicity, source sequence progression, ordinary base-table CLONE, and view/external-table controls. ### Issue-to-test proof - The live sequence CLONE and LIKE statements now return `is not BASE TABLE`; both target table and column catalog counts remain zero, and the source remains `relkind = 'S'`. - The named-snapshot sequence CLONE returns the same error, leaves no target table or columns, and does not alter the source's next value. - The ordinary base-table CLONE still creates an `r` table with the original row. - View and external-table CLONE retain the same non-BASE-TABLE rejection and leave no targets. ### Tests run - `make thirdparties` - `make cgo` - `make build` - `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestBuildCreateTableLikeAndCloneRejectsSequenceSource$' ./pkg/sql/plan` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/plan` - `GOWORK=off go build -mod=readonly ./pkg/sql/plan` - `GOWORK=off go vet -mod=readonly ./pkg/sql/plan` - Distributed `clone_sequence` BVT: 34/34, 100% success; generated results were manually checked against the SQL semantics. ### Compatibility and residual risk The production change is one additional source-relkind check in the existing shared non-base-table guard. It does not alter sequence storage or the physical clone executor, and it preserves ordinary base-table, view, and external-table behavior. Supporting sequence duplication remains intentionally out of scope; sequence-specific cloning would require a separate operation that preserves `relkind = 'S'` and sequence invariants. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27050
What this PR does / why we need it:
Root cause
CREATE TABLE ... CLONEresolves its source and then reuses the sharedbuildCreateTableLIKE/CLONE rewrite path. That path rejected views and external tables but allowedcatalog.SystemSequenceRelto fall through. The bare CREATE TABLE rewrite therefore changed the source's internal seven-column sequence relation into an ordinary writable table, after which sequence functions rejected the target because it no longer had sequence relkind.Changes
SystemSequenceRelwith the existing... is not BASE TABLEvalidation before the CREATE TABLE rewrite and physical clone.Issue-to-test proof
is not BASE TABLE; both target table and column catalog counts remain zero, and the source remainsrelkind = 'S'.rtable with the original row.Tests run
make thirdpartiesmake cgomake build.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestBuildCreateTableLikeAndCloneRejectsSequenceSource$' ./pkg/sql/plan.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/planGOWORK=off go build -mod=readonly ./pkg/sql/planGOWORK=off go vet -mod=readonly ./pkg/sql/planclone_sequenceBVT: 34/34, 100% success; generated results were manually checked against the SQL semantics.Compatibility and residual risk
The production change is one additional source-relkind check in the existing shared non-base-table guard. It does not alter sequence storage or the physical clone executor, and it preserves ordinary base-table, view, and external-table behavior. Supporting sequence duplication remains intentionally out of scope; sequence-specific cloning would require a separate operation that preserves
relkind = 'S'and sequence invariants.