Skip to content

fix: preserve expression defaults in SHOW CREATE TABLE and CLONE - #27136

Merged
mergify[bot] merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27101-b950a2d2
Aug 14, 2026
Merged

mergify[bot] merged 3 commits into
matrixorigin:mainfrom
gouhongshen:agent/issue-27101-b950a2d2

Conversation

@gouhongshen

@gouhongshen gouhongshen commented Aug 14, 2026 •

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 #27101

What this PR does / why we need it:

Root cause

ConstructCreateTableSQL formats every non-NULL default through formatStr. That helper is correct for a literal default, but Default.OriginString is also used for already-formatted SQL expressions. As a result, the quote in nextval('seq') was escaped as string content and reconstructed DDL contained the invalid nextval(''seq''). SHOW CREATE TABLE and both CLONE paths reuse this reconstruction.

Changes

  • Pass the planned default expression into the shared default formatter.
  • Preserve OriginString verbatim for non-literal default expressions, while retaining the existing literal escaping and parenthesized-expression behavior.
  • Add a planner regression case that reconstructs and asserts DEFAULT nextval('seq'), plus a DEFAULT 42 literal control.
  • Add a distributed regression covering SHOW CREATE TABLE, table-level CLONE, database-level CLONE, row preservation, target table existence, and the literal-default control at both clone scopes.

Issue-to-test proof

  • SHOW CREATE TABLE: the planner unit test asserts the generated DDL contains DEFAULT nextval('seq'); the BVT also records the exact SHOW output and then exercises the same reconstructed DDL through both clone paths, which would fail on the previous nextval(''seq'') output.
  • Table-level CLONE: the BVT creates cloned sequence-default and literal-default tables, verifies both target tables exist, and verifies the source row/default value is preserved.
  • Database-level CLONE: the BVT clones the source database, verifies both tables exist, and verifies the sequence-default row and literal default are preserved.

Tests run

  • make build
  • .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^Test_buildTestShowCreateTable$' ./pkg/sql/plan (focused regression)
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/sql/plan (full package; passed)
  • mo-tester generated and independently reran test/distributed/cases/git4data/clone/clone_default_expression.sql against this build; 25/25 SQL statements passed.

Residual risks and scope

This PR fixes DDL reconstruction of default expressions. It does not change sequence-object cloning or sequence-to-table semantics tracked by the related issues #27049 and #27050. Legacy catalog entries with no planned default expression retain the previous formatter behavior.

@mergify mergify Bot added the kind/bug Something isn't working label Aug 14, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Aug 14, 2026
@gouhongshen
gouhongshen marked this pull request as ready for review August 14, 2026 02:29
@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 →

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

Reviewed exact head d1146f95b9850a594df9471b7afb0f9d99b89893. DDL reconstruction now distinguishes planned non-literal expressions from literal defaults, preserving quoted function arguments such as nextval('seq') while retaining literal escaping and the existing parenthesized-expression path. The public SHOW CREATE, table-clone, and database-clone regressions exercise the shared formatter and literal control. Focused exact-head plan tests and additional expression-default probes pass; all required checks are green. No blocker found.

@aptend aptend 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 completed on exact head d1146f9. The change correctly distinguishes persisted literal defaults from non-literal planned expressions: literal spellings retain the existing escaping path, parenthesized expression defaults retain their established verbatim contract even after constant folding, and non-literal expressions such as nextval with a quoted argument are no longer corrupted by treating the complete SQL expression as string content. I traced the shared reconstruction path used by SHOW CREATE, table CLONE, and database CLONE, and checked the source Default construction contract and the sequence-cloning scope boundaries. The focused planner regression passed 10/10 with the required local CGo setup, the distributed case covers both clone scopes and literal controls, all exact-head CI checks are terminal and green/skipped, and git diff --check is clean. LGTM.

@mergify

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

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

Reviewed exact head d1146f9. The change correctly distinguishes planned literals from SQL default expressions, preserves the existing literal escaping and parenthesized-expression behavior, and closes the SHOW/CLONE malformed-DDL path without broadening runtime semantics. Focused and full pkg/sql/plan tests, go vet, and diff checks passed locally.

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

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-14 03:55 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-14 05:13 UTC · at 3c547ea2952d4f7fcc8bd8410ae70a60cf3d8d1a · squash

This pull request spent 1 hour 17 minutes 37 seconds in the queue, including 1 hour 3 minutes 21 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@mergify
mergify Bot merged commit 6e282d2 into matrixorigin:main Aug 14, 2026
25 of 26 checks passed
@mergify mergify Bot removed the queued label Aug 14, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…rixorigin#27136)

### Root cause

`ConstructCreateTableSQL` formats every non-NULL default through `formatStr`. That helper is correct for a literal default, but `Default.OriginString` is also used for already-formatted SQL expressions. As a result, the quote in `nextval('seq')` was escaped as string content and reconstructed DDL contained the invalid `nextval(''seq'')`. SHOW CREATE TABLE and both CLONE paths reuse this reconstruction.

### Changes

- Pass the planned default expression into the shared default formatter.
- Preserve `OriginString` verbatim for non-literal default expressions, while retaining the existing literal escaping and parenthesized-expression behavior.
- Add a planner regression case that reconstructs and asserts `DEFAULT nextval('seq')`, plus a `DEFAULT 42` literal control.
- Add a distributed regression covering SHOW CREATE TABLE, table-level CLONE, database-level CLONE, row preservation, target table existence, and the literal-default control at both clone scopes.

### Issue-to-test proof

- SHOW CREATE TABLE: the planner unit test asserts the generated DDL contains `DEFAULT nextval('seq')`; the BVT also records the exact SHOW output and then exercises the same reconstructed DDL through both clone paths, which would fail on the previous `nextval(''seq'')` output.
- Table-level CLONE: the BVT creates cloned sequence-default and literal-default tables, verifies both target tables exist, and verifies the source row/default value is preserved.
- Database-level CLONE: the BVT clones the source database, verifies both tables exist, and verifies the sequence-default row and literal default are preserved.

### Tests run

- `make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^Test_buildTestShowCreateTable$' ./pkg/sql/plan` (focused regression)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/sql/plan` (full package; passed)
- mo-tester generated and independently reran `test/distributed/cases/git4data/clone/clone_default_expression.sql` against this build; 25/25 SQL statements passed.

### Residual risks and scope

This PR fixes DDL reconstruction of default expressions. It does not change sequence-object cloning or sequence-to-table semantics tracked by the related issues matrixorigin#27049 and matrixorigin#27050. Legacy catalog entries with no planned default expression retain the previous formatter behavior.

Approved by: @aunjgr, @aptend, @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…rixorigin#27136)

### Root cause

`ConstructCreateTableSQL` formats every non-NULL default through `formatStr`. That helper is correct for a literal default, but `Default.OriginString` is also used for already-formatted SQL expressions. As a result, the quote in `nextval('seq')` was escaped as string content and reconstructed DDL contained the invalid `nextval(''seq'')`. SHOW CREATE TABLE and both CLONE paths reuse this reconstruction.

### Changes

- Pass the planned default expression into the shared default formatter.
- Preserve `OriginString` verbatim for non-literal default expressions, while retaining the existing literal escaping and parenthesized-expression behavior.
- Add a planner regression case that reconstructs and asserts `DEFAULT nextval('seq')`, plus a `DEFAULT 42` literal control.
- Add a distributed regression covering SHOW CREATE TABLE, table-level CLONE, database-level CLONE, row preservation, target table existence, and the literal-default control at both clone scopes.

### Issue-to-test proof

- SHOW CREATE TABLE: the planner unit test asserts the generated DDL contains `DEFAULT nextval('seq')`; the BVT also records the exact SHOW output and then exercises the same reconstructed DDL through both clone paths, which would fail on the previous `nextval(''seq'')` output.
- Table-level CLONE: the BVT creates cloned sequence-default and literal-default tables, verifies both target tables exist, and verifies the source row/default value is preserved.
- Database-level CLONE: the BVT clones the source database, verifies both tables exist, and verifies the sequence-default row and literal default are preserved.

### Tests run

- `make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^Test_buildTestShowCreateTable$' ./pkg/sql/plan` (focused regression)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/sql/plan` (full package; passed)
- mo-tester generated and independently reran `test/distributed/cases/git4data/clone/clone_default_expression.sql` against this build; 25/25 SQL statements passed.

### Residual risks and scope

This PR fixes DDL reconstruction of default expressions. It does not change sequence-object cloning or sequence-to-table semantics tracked by the related issues matrixorigin#27049 and matrixorigin#27050. Legacy catalog entries with no planned default expression retain the previous formatter behavior.

Approved by: @aunjgr, @aptend, @XuPeng-SH
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…rixorigin#27136)

### Root cause

`ConstructCreateTableSQL` formats every non-NULL default through `formatStr`. That helper is correct for a literal default, but `Default.OriginString` is also used for already-formatted SQL expressions. As a result, the quote in `nextval('seq')` was escaped as string content and reconstructed DDL contained the invalid `nextval(''seq'')`. SHOW CREATE TABLE and both CLONE paths reuse this reconstruction.

### Changes

- Pass the planned default expression into the shared default formatter.
- Preserve `OriginString` verbatim for non-literal default expressions, while retaining the existing literal escaping and parenthesized-expression behavior.
- Add a planner regression case that reconstructs and asserts `DEFAULT nextval('seq')`, plus a `DEFAULT 42` literal control.
- Add a distributed regression covering SHOW CREATE TABLE, table-level CLONE, database-level CLONE, row preservation, target table existence, and the literal-default control at both clone scopes.

### Issue-to-test proof

- SHOW CREATE TABLE: the planner unit test asserts the generated DDL contains `DEFAULT nextval('seq')`; the BVT also records the exact SHOW output and then exercises the same reconstructed DDL through both clone paths, which would fail on the previous `nextval(''seq'')` output.
- Table-level CLONE: the BVT creates cloned sequence-default and literal-default tables, verifies both target tables exist, and verifies the source row/default value is preserved.
- Database-level CLONE: the BVT clones the source database, verifies both tables exist, and verifies the sequence-default row and literal default are preserved.

### Tests run

- `make build`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^Test_buildTestShowCreateTable$' ./pkg/sql/plan` (focused regression)
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=600s ./pkg/sql/plan` (full package; passed)
- mo-tester generated and independently reran `test/distributed/cases/git4data/clone/clone_default_expression.sql` against this build; 25/25 SQL statements passed.

### Residual risks and scope

This PR fixes DDL reconstruction of default expressions. It does not change sequence-object cloning or sequence-to-table semantics tracked by the related issues matrixorigin#27049 and matrixorigin#27050. Legacy catalog entries with no planned default expression retain the previous formatter behavior.

Approved by: @aunjgr, @aptend, @XuPeng-SH

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]: SHOW CREATE TABLE and CLONE fail for tables with DEFAULT nextval(...)

5 participants