Skip to content

fix: reject sequence sources in table clone - #27118

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27050-df4ff0b3
Aug 13, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27050-df4ff0b3

Conversation

@gouhongshen

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #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.

@mergify mergify Bot added the kind/bug Something isn't working label Aug 13, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Aug 13, 2026
@gouhongshen
gouhongshen marked this pull request as ready for review August 13, 2026 13:01
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

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.

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.

@mergify mergify Bot added the queued label Aug 13, 2026
@mergify

mergify Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-13 18:51 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-08-13 18:51 UTC · at f460f513470f6c64b32132b7561072b7a8e63cba

This pull request spent 18 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/sca-go-module-cache.yaml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@mergify mergify Bot added dequeued and removed queued labels Aug 13, 2026
@XuPeng-SH
XuPeng-SH merged commit a6a6d09 into matrixorigin:main Aug 13, 2026
21 of 23 checks passed
@mergify mergify Bot removed the dequeued label Aug 13, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## 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]>

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CREATE TABLE ... CLONE converts a sequence into a writable base table

3 participants