Repository navigation
fix(plan): resolve DELETE targets in their source scope - #31795
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
44d639b to
5390dc4
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 5390dc411b2af9442bbf211b9cdd72211a89553b
Assessment: approve
DELETE target identity is handled consistently across both planners and read-only admission. No actionable findings.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
Validation:
-
Targeted planner/frontend checks and all 17 public SQL scenarios passed.
-
Full planner package passed. Frontend had one read-only-checkout export failure; that test passed when rerun from a writable directory.
-
go vet passed for all three affected packages; formatting, discussion coverage and unchanged-source audits passed.
-
Commands, exits and retained logs are reconciled in validation-evidence.json.
Limitations:
-
Relevant CI was pending in the frozen evidence.
-
Author-reported race, configured-linter and mo-tester runs were not independently reproduced.
5390dc4 to
1686da0
Compare
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 1686da05d4b0d50e1aff9e1023abdf3449b2d05d
Assessment: approve
DELETE target identity is consistent across both planners and read-only admission. No actionable findings remain.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
Validation:
-
Focused normal/race tests and public SQL scenarios passed.
-
Full planner passed. Frontend’s sole filesystem-environment failure passed using the unchanged test binary from a writable directory.
-
Exact mo-tester case passed twice: 17/17 checks per run, with teardown verified.
-
Formatting, vet, pinned molint and incremental golangci-lint passed.
-
Source remained unchanged; discussion coverage, receipts and logs are reconciled in attempt-1/validation-evidence.json.
Limitations:
-
Relevant CI remained pending in the frozen evidence.
-
Existing skipped tests remain unvalidated; broader integration suites and multi-CN testing were not run.
## 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: 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.
## What type of PR is this? - [ ] API-change - [x] 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: The combination of #31795 and #31798 left a boolean return in a function that now returns `writeDisposition`, breaking the main build. Return `writePersistent` for an unresolved or derived DELETE source, preserving the existing fail-closed behavior. The same one-line correction is proposed in #31813; that PR's main CI is currently blocked by its preflight description check. Validation on darwin/arm64, Go 1.27.1, `GOEXPERIMENT=simd`: - Full `pkg/frontend` unit suite passed (`-count=1`). - Affected read-only classification tests passed with `-race -count=1`, including the existing derived-source case. - Configured incremental SCA for `./pkg/frontend` passed with 0 issues. GitHub CI is pending.
… scopes (#31819) ## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #31794; follows the DELETE fix in #31795 with INSERT and UPDATE scope corrections. ## What this PR does / why we need it: A CTE sharing a DML target name could make INSERT panic or make UPDATE resolve the wrong writable namespace. INSERT must write its physical catalog target while resolving its source through lexical CTE scopes. UPDATE must respect source binding: an unqualified CTE is read-only, a schema-qualified physical table remains writable, and ambiguous or wrong-schema assignments must fail before any write. Reuse existing CTE registration and column binding to enforce those rules in modern and legacy INSERT, normal and Iceberg UPDATE, and FK metadata lookup. UPDATE FK checks reuse the upstream unified DMLContext; the removed metadata resolver is not restored. Preserve nested WITH shadowing, UPDATE FROM target scope, JOIN USING column selection, generated-column DEFAULT, and reusable ASTs. Keep frontend read-only admission and clone-routine dependency collection consistent with the same physical-target rules, including multi-insert dependency collection. No additional catalog round trips or per-row execution work; the changes stay in planning and existing statement traversal. Validation: - Independent MySQL 8.0 reference: 15 target/scope controls; clean-base probes reproduce both INSERT planner panics and UPDATE namespace errors. - Planner race coverage: full `go test -race -short -count=1 -p=1 -timeout=20m ./pkg/sql/plan` completed with only two forward-reference diagnostic-text assertion failures. Corrected the expected text and reran the entire affected `TestInsertCTEDeclarationScopeErrors` function under race: PASS. Production planner files were byte-identical across these runs; this is combined evidence, not a claim of a final full-suite green run. - Affected frontend race tests: 24 root tests / 107 subcases passed, covering read-only admission, remapping and clone dependencies. - Real embedded SQL integration: `TestDeleteCTETargetScope` passed under race, including 42 subcases with exact result rows, rejected-write checks, rollback, qualified UPDATE in read-only transactions and existing DELETE behavior. Reuses the existing cluster fixture. - `go vet`, configured golangci-lint (0 issues), and the Makefile-pinned `molint check -mod=readonly` passed for `./pkg/sql/plan ./pkg/frontend ./pkg/tests/sqlintegration`. - Original design/code review: Terra / max. After rebasing onto `4ca0d77748`, self-review of the upstream interaction and conflict adaptations found no unresolved blockers; this is not a new independent review. Compatibility limits: legacy INSERT VALUES scalar subqueries retain their independently verified pre-existing NYI; modern INSERT supports the covered case. Some qualified CTE assignment errors retain MatrixOne's existing absent-table diagnostic rather than MySQL's exact error code. CTE writes are rejected. Remote CI is pending. Rebase validation (base `4ca0d77748`, head `f2ccf261f7`): focused INSERT/UPDATE/CTE/Iceberg race tests, upstream UPDATE ownership/FK route race tests, affected frontend race tests, and all 42 real SQL subcases passed. Three-package vet, configured incremental golangci-lint (0 issues), pinned molint and diff checks passed. The base itself contained a DELETE admission branch returning `true` from the new `writeDisposition` function; exact-base overlay vet reproduced that compile failure. Return `writePersistent` to preserve its fail-closed behavior. CI follow-up (`9c722237c2`): coverage producer [job 123877532110](https://github.com/matrixorigin/matrixone/actions/runs/40998451616/job/123877532110) failed in `TestCrossTargetUpgradeRecovery` while reacquiring test-cluster admission after an intentionally interrupted startup. The third Start waited 164.081s and exhausted the test's aggregate 180s deadline; 17 other admissions succeeded during that wait. Coverage aggregation failed its producer prerequisite, not a coverage-rate check. Reuse the existing recovery starter with the same three-minute aggregate workload budget, keeping admission/startup under the test deadline and refreshing SQL contexts after each generation. Exclude canceled startup time too, preserve the explicit Stop watchdog, and join the asynchronous starter on early failure before cleaning up its budget. This changes test budget ownership, with no production scheduling, pool-size, sleep, retry or skip changes. The expanded simulated-clock error/retry control fails against the old helper immediately; final real recovery and all six budget controls pass with `-race -cover -covermode=atomic` (28.364s). Incremental embed vet, configured lint and pinned molint pass. Remote CI on the follow-up commit remains pending.
What type of PR is this?
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 entrydiagnostic. 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.