Commit 092ba64
authored
to 3.0: fix: force CTAS follow-up insert to run on one CN (#23749)
## What type of PR is this?
- [ ] API-change
- [x] 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).1 parent e9eeb34 commit 092ba64
1 file changed
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1497 | 1497 | | |
1498 | 1498 | | |
1499 | 1499 | | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
1500 | 1503 | | |
1501 | 1504 | | |
1502 | 1505 | | |
| |||
1761 | 1764 | | |
1762 | 1765 | | |
1763 | 1766 | | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
1764 | 1770 | | |
1765 | 1771 | | |
1766 | 1772 | | |
| |||
0 commit comments