Skip to content

refactor(sql): share DELETE target name resolution - #31786

Merged
XuPeng-SH merged 4 commits into
mainfrom
codex/29249-dml-target-ownership
Oct 29, 2026
Merged

XuPeng-SH merged 4 commits into
mainfrom
codex/29249-dml-target-ownership

Conversation

@XuPeng-SH

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:

Refs #29249

What this PR does / why we need it:

READ ONLY admission and the modern/legacy DELETE planners independently implemented the rules that map a DELETE target alias to its source table. A qualified target such as DELETE db.x FROM p AS x must identify p consistently before applying temporary-table and catalog policies.

Share the pure alias collection and name substitution in pkg/sql/plan, and remove the duplicated implementations. Each consumer retains its existing CTE checks, effective database resolution, catalog validation and transaction admission ordering. Classification reads current temporary-table bindings without mutating a reused AST. The change keeps O(source nodes + targets) work and statement-local storage; no runtime speedup is claimed.

The design explains the ownership boundary and why UPDATE binding remains separate.

Validation on Go 1.27.1, darwin/arm64, GOEXPERIMENT=simd:

  • Full pkg/sql/plan and pkg/frontend UT: passed with -count=1; 3 pre-existing skips.
  • Affected DELETE/DML routing/READ ONLY tests: 28 root tests passed with -race -count=1.
  • Configured incremental make static-check-selected for both packages: passed, 0 issues.
  • Existing set/transaction_read_only.sql: 316/316 checks passed; same-instance rerun also 316/316, with teardown verified.
  • An external Go overlay disabling source-table substitution makes both planner-target and frontend-admission tests fail, confirming the new oracles detect wrong targets.

Local validation uses base b4cd00ee34f1; merge-result CI remains pending.

@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 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 9300af40d959883fc778c7ceaf0a93a255f25f2f

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 9300af40d959883fc778c7ceaf0a93a255f25f2f

Assessment: approve

The consolidation preserves DELETE target resolution, temporary-table admission, and planner routing. No actionable findings. Source remains unchanged.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • All 15 focused tests passed across planner and frontend.

  • Full planner suite passed. Frontend had one read-only-filesystem fixture failure; that unchanged test and its control passed with a diagnostic path-only overlay.

  • Both packages passed go vet; formatting and diff checks were clean.

  • Ten receipts reconciled with retained logs in validation-review.json; discussion-assessment.json covers both comments.

Limitations:

  • The original full frontend run remains non-passing; three existing tests/subtests were skipped across both packages.

  • Relevant frozen CI was pending. Author-reported BVT, race, mutation, and configured-linter results were not independently verified; configured linters were unavailable locally.

@XuPeng-SH
XuPeng-SH merged commit abc5e08 into main Oct 29, 2026
29 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/29249-dml-target-ownership branch October 29, 2026 23:11
XuPeng-SH added a commit that referenced this pull request Oct 30, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #31794

## What this PR does / why we need it:

A WITH name matching a DELETE target alias could suppress the writable
table and cause a planner panic. Extend the shared source collector from
#31786 to retain visible source names and explicit-alias identity, then
validate CTE/writable targets before catalog lookup in modern and legacy
DELETE. SELECT retains the original WITH; INSERT/UPDATE handling is
unchanged.

Preserve main's qualified explicit-alias precedence, including an alias
identical to its base table name. Reject true CTE/derived targets,
absent writable sources and mismatched qualified implicit targets. The
frontend read-only gate consumes the same source map and fails closed
for missing sources; no parallel collector or AST mutation is
introduced. Missing targets preserve the existing `missing FROM-clause
entry` diagnostic. Work remains bounded by statement
sources/targets/CTEs, with no per-row execution change.

Validation (Go 1.27.1, darwin/arm64): full planner UT; affected
planner/frontend/public SQL tests with race; gofmt, vet, pinned molint
and incremental golangci-lint (0 issues). Local single-CN BVTs covering
the full DELETE directory plus CTE and read-only cases completed with
1,236 checks passed, 24 existing ignores and zero failures; the original
failing DELETE golden is unchanged. Database/account teardown verified.
Upstream target-identity and AST-reuse controls are retained. Design and
overall review: gpt-6.1-terra/max. GitHub CI is separate.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants