Repository navigation
fix: preserve expression defaults in SHOW CREATE TABLE and CLONE - #27136
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? |
aunjgr
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Queued — the merge queue status continues in this comment ↓. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
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.
Merge Queue Status
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
|
…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
…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
…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
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #27101
What this PR does / why we need it:
Root cause
ConstructCreateTableSQLformats every non-NULL default throughformatStr. That helper is correct for a literal default, butDefault.OriginStringis also used for already-formatted SQL expressions. As a result, the quote innextval('seq')was escaped as string content and reconstructed DDL contained the invalidnextval(''seq''). SHOW CREATE TABLE and both CLONE paths reuse this reconstruction.Changes
OriginStringverbatim for non-literal default expressions, while retaining the existing literal escaping and parenthesized-expression behavior.DEFAULT nextval('seq'), plus aDEFAULT 42literal control.Issue-to-test proof
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 previousnextval(''seq'')output.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)test/distributed/cases/git4data/clone/clone_default_expression.sqlagainst 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.