Repository navigation
fix(sql): resolve INSERT and UPDATE targets through their correct CTE scopes - #31819
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? |
8392064 to
f2ccf26
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: f2ccf261f74b6ddaad1ae966b5c6d766b4256b59
Assessment: approve
Reviewed the complete delta, discussion, linked issue, and affected consumers. INSERT/UPDATE scope handling and frontend behavior are consistent; no actionable defects remain.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
Validation:
-
Planner focused tests passed: 8 roots, 54 subcases. Full planner package passed in normal short mode.
-
Affected frontend tests passed: 17 roots, 93 subcases.
-
Real SQL integration passed all 42 TestDeleteCTETargetScope subcases.
-
go vet passed for all three changed packages.
-
Final audit confirmed frozen HEAD, unchanged source, matching patch, and complete discussion coverage. Receipts and logs are reconciled in validation-summary.json.
Limitations:
-
Full frontend package failed only in unchanged Test_openNewFile_nilCtx because it writes beneath the read-only checkout; retained in frontend-package.log.
-
Frozen CI remained pending. Author-reported race and MySQL comparison results were not independently verified.
|
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: 9c722237c29adbe72b50875e7e6d211b4d35af3f
Assessment: approve
The CTE target-scope fixes and recovery-test budget follow-up satisfy the reviewed contracts. No actionable defects remain.
Model: gpt-6-astra / xhigh
Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2
Validation:
-
TestCrossTargetUpgradeRecovery passed with race detection and atomic coverage in 25.62 seconds.
-
All six startup-budget controls passed initially and across 100 race/coverage repetitions, without failures or skips.
-
Embed go vet -race passed.
-
Reused verified planner, focused frontend, 42 SQL integration cases, and vet evidence; their inputs are unchanged.
-
Frozen-source, native-provenance, discussion-coverage, receipt and log checks passed. Records: /home/xupeng/.local/state/mo-bot/jobs/aa19038b3c2acdf9260c24c0/attempt-1/validation-summary.json.
Limitations:
-
Remote CI remains pending in the supplied evidence.
-
The reused full frontend run failed an unchanged fixture that writes into read-only source; affected frontend tests passed.
-
The full embed suite was not rerun. Author-reported MySQL comparison results were not independently verified.
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [x] Code Refactoring ## Which issue(s) this PR fixes: Refs #29249 Refs #31744 (current-main regression validation; not a new snapshot/frontier fix) ## What this PR does / why we need it: Repair shared ownership and test-cost problems identified while investigating 20 failed race/coverage jobs. Five coverage failures exhausted upgrade tests' 180/300-second workload deadlines while still waiting for runner-wide cluster admission. Other jobs exposed an actual statement-profile race, nondeterministic canceled Raft reads, and avoidable shell/GC fixture work. - Protect the SQL-source status getter with the existing statement-profile mutex, matching execution and reset. No second synchronization owner. - Reuse the existing recovery starter for CrossTarget and all COLUMNS/CDC staged upgrades. Preserve their original cumulative 3/5/10-minute workload budgets while excluding admission/startup time, including deliberately failed startup. Refresh each generation's SQL context; stop and join asynchronous startup on early failure before timer cleanup. Preserve global test timeouts and all manual-rejection, ablation, rollback, fencing, tenant, CDC and restart assertions. - Reject already-canceled logservice reads before admission/retry using the existing Dragonboat cancellation sentinel. Preserve missing/expired-deadline error precedence and completed-versus-canceled in-flight behavior. Check full and projected reads independently, including deadline controls. - Remove obsolete repair-walker waits and duplicate readbacks. The walker was removed upstream; versioned entries own convergence. These three static sleep sites formerly add 16 seconds over the selected seven upgrade scenarios. This is removed explicit waiting, not a measured whole-CI speedup. - Reduce timeout/cancellation mock-package staging without removing the timeout, TERM-to-KILL grace, process ownership, pool or drain-outcome assertions. Keep independent scenarios where mutable upgrade state or cancellation outcome differs. - Replace the legacy upgrade-GC test's 10ms ticker/5-second polling race with a synchronous call to the same registered collector owner. Preserve real registration and filesystem deletion, and additionally verify a recent neighbor is retained. The small explicit test seam adds no automatic runtime work. ### Latest rebase Rebased onto main `c42cf40214` (including #31489 and #31819). The overlapping recovery test retains both failed-start and canceled-start budget checks; all other PR-touched files are unchanged from the previous head. Local validation on this rebase: `TestCrossTargetUpgradeRecovery` and all seven `TestRecoveryClusterStartupBudget` cases pass with `-race`; embed go vet, pinned molint, incremental golangci-lint (0 issues), Go formatting, and diff checks pass. Earlier validation and patch hashes below refer to the previous base. ### Scheduling-preview and cancellation follow-up after rebase Rebased onto main `d1594899b7381c5f0d44fa4590d21da1b09fa109`; range-diff and byte comparison confirm that the rebase replay preserved the original PR patch before the two intentional test corrections below. The CI pool-resolution test raced a stage-specific assertion against the production preview's 100 ms end-to-end deadline. It now enters the resolver under a caller-owned context, confirms entry before canceling, and checks exact cancellation identity and stage attribution. The production-wrapper constant remains 100 ms; its separate blocked-discovery test checks bounded completion within 1 second, rather than asserting exact elapsed time. Cleanup has a test-owned emergency release and joins the worker before closing the session/mocks, so losing the caller context fails without hanging cleanup. The HAKeeper cancellation control also now owns a separate valid deadline instead of inheriting a short budget already consumed by preceding real reads. Missing-deadline and expired-deadline sentinels remain distinct. Neither correction changes production timeout or read behavior. Controlled overlays reproduce the earlier-expiry failures of both old tests. A lost-context mutation makes the revised preview test fail at its watchdog and exit cleanly. These expected failures are sensitivity/cleanup evidence, not passing UTs or proof of the remote runner's precise scheduling cause. Previous-base validation (`d1594899b7`): - Full normal packages (`-short`): embed PASS (358.220s; all nine changed cases executed), logservice PASS (63.811s; no skips), fileservice PASS (66.275s), and process PASS. Embed retains two unrelated skips (external MySQL CDC configuration and unconditional restart skip); fileservice retains six environmental/opt-in skips. Named optools, frontend and registered-GC consumers pass normal mode. - Both corrected tests pass 100 race repetitions each. Current-base process package, frontend/GC consumers, vector/BatchSet controls and the two-CN CrossTarget SQL/upgrade/restart scenario pass race checks. - Current full frontend/logservice/vector/batch package checks pass gofmt, vet, pinned molint and configured golangci-lint 2.14.0 (0 issues). No diff-filtered lint findings were omitted. - Independent `gpt-6.1-terra` / `max` design and overall review: PASS, no unresolved material blocker. Complete base-to-final-content patch SHA-256: `1f828f1191acace7b48ce005cc40196702ae984b0ad964b360ff59c561b765bf`. Earlier normal embed results below are author-reported historical evidence. Complete original-head ARM64 SCA (molint and golangci-lint over ./...) and original-head race package/checkpoint results are retained and reused only for semantically unchanged closures; the original UT job itself failed at the preview assertion. Raw UT JSON was truncated by the artifact producer; all eight embed batch completions are separately proven by the complete checkpoint log. New-base vector copy changes and the current frontend/read controls are validated separately. ### Historical author-reported validation on main base `75e3964473` - Full `pkg/embed` normal package: **PASS, 463.046s**. Focused recovery/CDC native scenarios and fake-clock error/retry/cancellation controls pass; affected asynchronous recovery scenarios under race: **PASS, 163.449s**. - Full `pkg/vm/process`, `pkg/logservice`, and `optools` race checks pass (2.284s, 67.666s and 30.020s respectively). Profile concurrent set/get/clear: 100 race rounds pass. Canceled-read regression: 100 race rounds pass before the final error-precedence refinement; the final complete logservice race run includes that refinement and its deadline controls. - Reported SQL integration/publication, PK reconnect, view-description and multi-CN index-rebuild consumers pass under race: 71.231s / 13.893s / 28.924s / 42.947s. Current-main EXPLAIN scheduling and LAG/LEAD rebuild controls also pass under race; their historical failures do not justify weakening assertions or importing unrelated feature changes. - Registered legacy GC and file-service GC/close neighbors pass under race. The exact legacy-GC case passes 100 race rounds (8.245s). A temporary registration mutation makes the real deletion assertion fail, confirming retained sensitivity. - Two temporary overlay probes force early failure after upgrade entry: both terminate with the expected test failure, release admission/ports, and report no data race or hang. Expected failures are negative-control evidence, not ordinary green tests. - Incremental gofmt, `go vet`, and configured golangci-lint over all six changed packages pass; lint reports zero new issues. Actual `gpt-6.1-terra` / `max` design and overall review performed. The frozen historical jobs are dispositioned below. Passing current-main controls do not prove that every historical load-related timeout has been eliminated. One job failed downloading Go before tests; JSON assertions exist only on its feature branch. There is no claim to fix those through unrelated kernel changes. No real long-admission-queue capacity benchmark or whole-CI speedup is claimed; admission isolation and the global timeout remain authoritative. New remote CI is pending. <details> <summary>All 20 historical failed-job dispositions</summary> | Job | Findings and disposition | |---|---| | [JSON conditional branches](https://github.com/matrixorigin/matrixone/actions/runs/41039528728/job/124008697181) | Branch-specific planner feature assertions; no same-named main test. No unrelated feature imported. | | [Prepared EXPLAIN](https://github.com/matrixorigin/matrixone/actions/runs/41041258684/job/124015050819) | Current-main normal and race controls pass unchanged. | | [CrossTarget admission](https://github.com/matrixorigin/matrixone/actions/runs/41058801997/job/124073182978) | Shared recovery-budget correction. | | [ENUM/SET racing](https://github.com/matrixorigin/matrixone/actions/runs/41047081386/job/124033759627) | Current-main native control and owning embed package pass; historical assertion was truncated. | | [LAG/LEAD rebuild](https://github.com/matrixorigin/matrixone/actions/runs/41056564312/job/124065620945) | Current-main normal and race controls pass unchanged. | | [Timeout harness + scalar refresh](https://github.com/matrixorigin/matrixone/actions/runs/41039493921/job/124008584360) | Trimmed harness setup; current-main scalar/tenant control passes. Heartbeat-load cause not established. | | [Index rebuild + view description](https://github.com/matrixorigin/matrixone/actions/runs/41039549319/job/124008769166) | Both current-main native race consumers pass; historical heartbeat stalls not independently reproduced. | | [Interrupted COLUMNS admission](https://github.com/matrixorigin/matrixone/actions/runs/41053938026/job/124056760282) | Shared recovery-budget correction; interrupted-route assertions retained. | | [Manual COLUMNS admission](https://github.com/matrixorigin/matrixone/actions/runs/41052998517/job/124053570526) | Shared budget and failed-start accounting; rejection/remedy retained. | | [Go setup download](https://github.com/matrixorigin/matrixone/actions/runs/41053037243/job/124053673864) | Infrastructure download timed out before UT; no source workaround. | | [HAKeeper cadence](https://github.com/matrixorigin/matrixone/actions/runs/41039511901/job/124008624807) | Compatible pre-admission cancellation correction and independent read/deadline assertions. | | [Cancellation harness + view](https://github.com/matrixorigin/matrixone/actions/runs/41039507021/job/124008594496) | Trimmed harness setup; current-main view race control passes. No claim that this proves a runner-load fix. | | [CDC cleanup](https://github.com/matrixorigin/matrixone/actions/runs/41039259320/job/124007793286) | Full current-main embed package passes; historical heartbeat/cleanup stall not independently reproduced. | | [ENUM/SET coverage](https://github.com/matrixorigin/matrixone/actions/runs/41047081386/job/124033818781) | Same feature-branch occurrence as racing; current-main native/owning-package controls pass. | | [Publication status race](https://github.com/matrixorigin/matrixone/actions/runs/41039517779/job/124008648159) | Shared statement-profile mutex fix; publication consumer passes race. | | [Forward-create replacement](https://github.com/matrixorigin/matrixone/actions/runs/41036050792/job/123997537166) | Current-main normal native control passes unchanged; no speculative heartbeat workaround. | | [GC and other embed failures](https://github.com/matrixorigin/matrixone/actions/runs/41034194666/job/123990966532) | Synchronous registered-GC correction; owning embed passes prepared-time, roles, catalog, CDC and bulk-write neighbors. | | [JSON + PK reconnect](https://github.com/matrixorigin/matrixone/actions/runs/41039528728/job/124008741932) | JSON branch-specific; current-main PK reconnect race control passes with existing snapshot/frontier assertions. | | [CrossTarget admission (second)](https://github.com/matrixorigin/matrixone/actions/runs/41039605054/job/124009054972) | Same shared recovery-budget correction. | | [No-entry COLUMNS admission](https://github.com/matrixorigin/matrixone/actions/runs/41039552794/job/124008923391) | Same shared budget correction; negative/positive across-generation controls retained. | </details> **Relationship to the owner's other open CI issues:** this PR does not close the remaining assigned flaky-test reports. #31744 names the PK reconnect case present in the 20-job sample; its current-main race validation passed, but the snapshot/frontier repair is not introduced by this diff. #31781 includes a separate snapshot-replay context shared across subtests and quoted-default cleanup timeouts; changing upgrade-startup budget ownership does not fix either mechanism. #31790 concerns flush-to-DUMP visibility, #31696 cross-CN DDL visibility, #31545 DROP cleanup, #31491 retired-owner route convergence, and #30985 hotfix timeout/diagnostic publication. Those require their own causal closure; none is claimed resolved or automatically closed here.
What type of PR is this?
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:
go test -race -short -count=1 -p=1 -timeout=20m ./pkg/sql/plancompleted with only two forward-reference diagnostic-text assertion failures. Corrected the expected text and reran the entire affectedTestInsertCTEDeclarationScopeErrorsfunction 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.TestDeleteCTETargetScopepassed 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-pinnedmolint check -mod=readonlypassed for./pkg/sql/plan ./pkg/frontend ./pkg/tests/sqlintegration.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, headf2ccf261f7): 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 returningtruefrom the newwriteDispositionfunction; exact-base overlay vet reproduced that compile failure. ReturnwritePersistentto preserve its fail-closed behavior.CI follow-up (
9c722237c2): coverage producer job 123877532110 failed inTestCrossTargetUpgradeRecoverywhile 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.