Skip to content

fix: do not retain AUTO_INCREMENT in CTAS result columns - #27475

Merged
mergify[bot] merged 11 commits into
matrixorigin:mainfrom
daviszhen:fix-ctas-autoincrement
Aug 24, 2026
Merged

mergify[bot] merged 11 commits into
matrixorigin:mainfrom
daviszhen:fix-ctas-autoincrement

Conversation

@daviszhen

@daviszhen daviszhen commented Aug 22, 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:

issue #24436

#24433

What this PR does / why we need it:

Do not copy a source column's AUTO_INCREMENT attribute into a table created by CREATE 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 with EXTRA=auto_increment.

This addresses the AUTO_INCREMENT item in #24436 / #24433.

Changes

  • Clear AutoIncr while constructing inferred CTAS columns.
  • Add a plan-level regression test.
  • Add a distributed BVT regression asserting source AUTO_INCREMENT count is 1 and CTAS target count is 0.

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

@daviszhen

Copy link
Copy Markdown
Contributor Author

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.

主要修改:

  • CTAS 清除源列 AUTO_INCREMENT 后,若源列没有普通默认值,则根据类型生成默认值(整数为 DEFAULT 0)。
  • 保持显式 CTAS 目标列声明优先,例如显式 DEFAULT 42 不会被覆盖。
  • 增加计划层测试、省略 id 插入测试及 BVT 用例

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

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

@mergify

mergify Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

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

@mergify

mergify Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-24 03:07 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • 🚫 Left the queue — 2026-08-24 03:08 UTC · at 086a62a2fdcd34ececb2d1d921cce9a04b89a636

This pull request spent 1 minute 18 seconds in the queue, with no time 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)

Reason

The pull request #27475 has been manually updated

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

@mergify

mergify Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-24 03:59 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-24 04:55 UTC · at d6969a0ff65e6ce12562f8bfe508164fa138772f · squash

This pull request spent 55 minutes 33 seconds in the queue, including 54 minutes 55 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)

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/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants