Skip to content

[4.2] fix(plan): preserve DELETE target scope - #31796

Merged
XuPeng-SH merged 4 commits into
4.2-devfrom
codex/issue31794-delete-cte-scope-4.2-dev
Oct 30, 2026
Merged

XuPeng-SH merged 4 commits into
4.2-devfrom
codex/issue31794-delete-cte-scope-4.2-dev

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 29, 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:

Fixes #31794

What this PR does / why we need it:

Adapt #31795 to 4.2-dev: resolve DELETE targets against their original FROM sources before CTE lookup/database defaulting. Modern and legacy DELETE share the validation; actual CTE/derived targets and mismatched qualified targets return errors before write planning. Generic INSERT/UPDATE behavior is unchanged. Explicit aliases retain their existing qualified-target precedence, including aliases spelled exactly like the base table; qualified implicit names must match their source.

Also use main's unrestricted-delete classification in both planners. The 4.2 legacy path previously treated a one-target join without WHERE/LIMIT as a full-table delete, enabling truncation or full-index cleanup even when the join selects only some rows. Joined/partitioned deletes retain row-based execution; ordinary unrestricted deletes keep their existing optimization.

Validation: full planner UT, affected DELETE tests with race, branch-configured incremental gofmt/vet/molint/golangci-lint, and twice-run mo-tester comparison (34/34 each) with teardown checks. Incremental golangci reports 0 issues; molint still reports three unchanged recovery diagnostics in expr_opt.go/returning.go, both identical to the base. BVT includes an outgoing-FK target that forces legacy planning and verifies remaining rows plus deleted/surviving unique-key entries. Local toolchain: Go 1.26.4, darwin/arm64. GitHub CI is separate.

Preserve the existing missing-FROM diagnostic when a DELETE target is not a writable source. This keeps the pre-existing multi-table DELETE SQL contract while both planner paths validate targets before writes. Regression coverage includes missing and alias-hidden targets, derived sources, and a missing second target with unchanged rows.

Additional CI-fix validation on Go 1.26.4, darwin/arm64: full planner UT passed; affected planner tests passed with -race -count=1; branch-configured incremental gofmt, vet and golangci-lint passed with 0 new issues. Molint reports the same three unchanged checkrecover diagnostics in expr_opt.go and returning.go as the 4.2 base. In a real three-CN local cluster, the previously failing delete_multiple_table.sql passed 113/115 with 2 existing ignored, and delete_target_scope.sql passed 38/38, with teardown checked.

The separate CI UT TestIssue26114LegacyCrossAccountMetadataCountsTowardTargetQuota timed out while waiting for a TN shard during cluster startup. One local run passed; this does not establish the CI timeout's cause. New CI results are pending.

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner October 29, 2026 23:25
@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: d53a6ff96ec6c9dfbc19ce5086bc9ce5fe99d365

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: d53a6ff96ec6c9dfbc19ce5086bc9ce5fe99d365

Assessment: approve

DELETE target resolution and joined-delete cleanup are consistent across both planners. No actionable defects remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • Isolation preflight passed; native prerequisites matched frozen source inputs.

  • 12 focused planner tests and 35 subtests passed. Evidence: planner-test.log and checks/1793316756672259710-3.json.

  • Source remained unchanged; diff whitespace check passed.

  • Complete discussion accounting and check reconciliation saved in discussion-assessment.json and validation-report.json.

Limitations:

  • End-to-end SQL and race tests were not rerun locally; author execution claims lack attached logs.

  • Relevant CI jobs remained in progress in the supplied snapshot.

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: b027d9fb5e905906b2ea271dd93617e313cbab14

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: b027d9fb5e905906b2ea271dd93617e313cbab14

Assessment: approve

Target resolution preserves explicit-alias behavior, and joined deletes retain row-scoped table and index cleanup. No actionable findings.

Model: gpt-6-astra / xhigh

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

Validation:

  • 12 focused planner tests and 43 subtests passed.

  • Full planner package and go vet passed.

  • All 34 BVT statements passed twice through the public MySQL frontend, with row, error, unique-key and teardown assertions.

  • Formatting, discussion coverage and unchanged-source audits passed; receipts and logs are reconciled in validation-evidence.json.

Limitations:

  • Relevant CI remained pending in the supplied snapshot.

  • Public SQL validation used a diagnostic probe; mo-tester, race and configured linters were not independently rerun.

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 74e5a6108bed6fe5f9c7ea787eca2577f1a6ec4f

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: 74e5a6108bed6fe5f9c7ea787eca2577f1a6ec4f

Assessment: approve

DELETE target validation correctly separates CTE scope from writable aliases and preserves row-scoped cleanup for joined deletes. No actionable findings remain.

Model: gpt-6-astra / xhigh

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

Validation:

  • Full planner package passed: 1,688 top-level tests and 2,919 subtests, including all 46 new subtests.

  • All 38 SQL regression statements passed twice through the MySQL frontend on a three-CN embedded cluster, including rollback, expected errors, unique-index integrity and cleanup.

  • Five successful receipts reconciled with retained logs in validation-evidence.json. Source remains unchanged; all six discussion entries assessed.

Limitations:

  • Three existing unrelated planner subtests were skipped.

  • The public SQL diagnostic did not run mo-tester or assert result metadata. Race tests and configured linters were not rerun locally; relevant CI was pending in the supplied snapshot.

  • The linked issue's later INSERT/UPDATE reports remain outside this DELETE backport.

@XuPeng-SH
XuPeng-SH merged commit 44bcfda into 4.2-dev Oct 30, 2026
10 of 11 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue31794-delete-cte-scope-4.2-dev branch October 30, 2026 03:21

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/bug Something isn't working 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