Skip to content

to 3.0: fix: force CTAS follow-up insert to run on one CN#23749

Merged
heni02 merged 1 commit intomatrixorigin:3.0-devfrom
gouhongshen:fix/ctas-internal-insert-onecn
Feb 14, 2026
Merged

to 3.0: fix: force CTAS follow-up insert to run on one CN#23749
heni02 merged 1 commit intomatrixorigin:3.0-devfrom
gouhongshen:fix/ctas-internal-insert-onecn

Conversation

@gouhongshen
Copy link
Contributor

@gouhongshen gouhongshen commented Feb 14, 2026

What type of PR is this?

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

Which issue(s) this PR fixes:

issue ##23744

What this PR does / why we need it:

For CTAS, table creation and data population now happen in the same transaction.
the newly created target table (including hidden auto-increment/fake-pk metadata), causing pre-insert auto-increment
lookup to fail as no such table.

Fix

Before executing the CTAS follow-up internal SQL (createAsSelectSql), mark the current transaction as having DDL:

  • pkg/sql/compile/ddl.go (normal CTAS path)
  • pkg/sql/compile/ddl.go (temp table CTAS path)

This makes the internal SQL compile path choose one-CN execution, so the follow-up insert runs on the coordinator CN
and can access uncommitted metadata in the same transaction.

Why This Is Safe

  • Scope is limited to CTAS internal follow-up SQL only.
  • No user-visible SQL semantics are changed.
  • This is a correctness-first mitigation; only CTAS internal insert distribution is constrained.

Impact

  • Fixes CTAS failures in multi-CN for same-transaction create+insert scenarios.
  • Potentially reduces parallelism for CTAS follow-up insert (expected and acceptable for correctness).

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/XS Denotes a PR that changes [1, 9] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants