Repository navigation
fix: do not retain AUTO_INCREMENT in CTAS result columns - #27475
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 of exact head e35ac901f4d8677ae0f8b302366f51950816ca60.
[P1] Preserve a usable default when clearing inferred AUTO_INCREMENT (pkg/sql/plan/build_ddl.go:1316).
For a source id INT NOT NULL AUTO_INCREMENT, this line clears AutoIncr, but the following default construction leaves Default{NullAbility:false, Expr:nil} because an auto-increment source has no ordinary default to inherit. A later INSERT that omits id reaches getDefaultExpr and deterministically fails with invalid default value for column id. I reproduced that failure against this exact head with the plan builder.
MySQL CTAS produces id int NOT NULL DEFAULT 0 for this case (also the expected schema recorded in #24433), so omitting id remains valid there. This patch therefore changes the target from a generated column into an unusable required column instead of completing the CTAS behavior.
Please materialize the type default when stripping an inherited auto-increment attribute; the existing ctasViewTypeDefaultOrigin / buildCTASDefaultFromOrigin path already yields 0 for integer types. Add assertions for the default metadata and an omitted-id insert, while keeping explicit CTAS target declarations authoritative.
主要修改:
|
aptend
left a comment
There was a problem hiding this comment.
Reviewed exact head 086a62a2fdcd34ececb2d1d921cce9a04b89a636.
The prior blocking case is closed: inferred CTAS columns no longer retain the source AUTO_INCREMENT bit, a non-null inherited auto-increment column receives the typed default (0 for the covered integer case), omitted-column INSERT planning succeeds, and an explicit CTAS target default remains authoritative. I also checked nullable query boundaries and the full current diff; no new blocking issue found.
Validation passed: go list, go build, go vet, and full tests for pkg/sql/plan and pkg/sql/compile; focused CTAS tests passed with -race -count=20; git diff --check passed.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head 086a62a. The prior blocker is closed: inferred CTAS columns drop inherited AUTO_INCREMENT and materialize the typed default when the non-null source has no ordinary default, so omitted-column INSERT planning remains valid; explicit CTAS target defaults and explicit AUTO_INCREMENT declarations remain authoritative. I also exercised direct, derived-table, and CTE provenance boundaries with temporary counterexample tests. No resource, wait, or unbounded-growth issue found. Build, vet, focused repeated tests, full pkg/sql/plan and pkg/sql/compile tests, diff check, and current-main merge-tree passed.
|
Queued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 1 minute 18 seconds in the queue, with no time running CI. Required conditions to merge
ReasonThe pull request #27475 has been manually updated Requeued — the merge queue status continues in this comment ↓. |
Merge Queue Status
This pull request spent 55 minutes 33 seconds in the queue, including 54 minutes 55 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #24436
#24433
What this PR does / why we need it:
Do not copy a source column's
AUTO_INCREMENTattribute into a table created byCREATE TABLE ... AS SELECT.The CTAS result schema is a new table schema; MySQL does not retain the source auto-increment attribute. MatrixOne previously propagated
Typ.AutoIncr, so both the source and CTAS target were exposed withEXTRA=auto_increment.This addresses the AUTO_INCREMENT item in #24436 / #24433.
Changes
AutoIncrwhile constructing inferred CTAS columns.AUTO_INCREMENTcount is 1 and CTAS target count is 0.