Repository navigation
fix: enforce unique checks in multi-target UPDATE - #32821
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? |
|
This pull request is merged. |
|
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: 36519ecf04be262d8c320f2f7b28319630e0c609
Assessment: approve
Physical-target UNIQUE checks now cover merged rows through existing selector and dedup owners. The separate IGNORE path is preserved; no actionable defects remain.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed the complete delta, affected consumers, linked issue #31824 and all discussion entries.
-
Exact-function helper probe passed three tests covering 512 ownership configurations. Source, formatting, provenance and receipt audit passed; see validation-evidence.json.
-
Considered author-reported planner, SQL regression, repeated-alias control, build and vet passes within their stated scope.
Limitations:
-
Local planner tests could not compile because native prerequisites were unavailable; author execution logs were not supplied.
-
Frozen CI contains ancillary checks only; no substantive CI pass is claimed.
|
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: 1798127932cf129684375d2124bbbd46b444d341
Assessment: approve
UNIQUE checks use existing physical-row selectors and DEDUP owners to validate merged final rows once per index. IGNORE keeps its separate arbitration. Added typed and SQL regressions preserve independent correctness oracles; no actionable defect remains.
Model: gpt-6.1-sol / max
Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0
Validation:
-
Reviewed all four changed files, affected merge/selector/key/DEDUP consumers, linked issue comments and all five discussion entries.
-
Frozen source/patch, diff and Go-format checks passed. Production matches the previously reviewed revision; new test oracles were reviewed independently.
-
Three source-extracted helper tests passed through the supplied test-exec, covering two 512-configuration matrices, idempotence and index identity/order.
-
Frozen exact-head shared-build CI succeeded. Reused author-reported planner, SQL, race, two-CN, cancellation/rollback/retry and matched performance evidence within its stated scope.
Limitations:
-
Local native planner tests stopped before compilation because matching libmo/third-party prerequisites were unavailable. The helper probe does not execute SQL or native operators.
-
Frozen UT, SCA, coverage and multi-CN BVT CI remained in progress. The separately documented pre-existing UPDATE IGNORE duplicate-key defect is outside this fix.
975257b to
cc94699
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: cc94699c76dd1799ce36d64be1e7130de09d18cc
Assessment: approve
UNIQUE checks now validate merged final rows once per physical index, catching existing-key and intra-statement conflicts while preserving atomicity and the separate IGNORE arbitration. Reusing the existing physical-row selector and DEDUP owners is coherent; the additional selector establishes the merged row domain shared with physical writes. Complete source, tests and discussion review found no actionable defect.
Model: gpt-6.1-sol / max
Session: 01a1a004-9884-72c0-ad39-f096c4209c4a · slot 1 · generation 0
Validation:
-
Full normal ./pkg/sql/plan run passed 5,065 test roots, including all three added roots; two existing unrelated subtests skipped. See planner-package.jsonl and validation-review.json.
-
New public SQL regression and existing repeated-alias constraint control both passed twice in one process on the canonical two-CN fixture, with no skips. Covers alias orders, existing/same-new-key conflicts, NULL, single/composite/prefix/multiple unique indexes, row merging, one-to-many joins, other-table atomic rollback, index consistency and retry.
-
Assigned merge-base production control failed both selected required duplicate-error assertions because conflicting statements returned success. The candidate passes both. This expected failing control is retained separately in baseline-red.jsonl with exact-base overlay provenance.
-
Diagnostic cross-CN probe passed all four single/composite-index writer/observer cases across both CNs, including conflict rejection, unchanged full/index reads, successful-update visibility and fixture close. Existing TestUpdateIgnoreRepeatedAliasesAdvanceGreedily also passed.
-
go vet ./pkg/sql/plan ./pkg/tests/issues, changed-file gofmt and diff checks passed. Native prerequisites were built using repository Makefiles; source-audit.json verifies 196 native input hashes, artifact provenance, exact frozen source and patch content.
-
All seven discussion keys are reconciled in discussion-assessment.json. validation-review.json matches each claimed local check to its source/command/exit receipt and retained stdout/stderr.
Limitations:
-
Frozen current-head substantive CI remains in progress; no UT, SCA, coverage or BVT CI pass is inferred from pending jobs.
-
Local execution used normal mode. Author-reported race, larger-workload and benchmark results lack supplied raw receipts/logs and are not independently certified; no measured performance improvement is claimed.
-
The separately documented preexisting same-new-key UPDATE IGNORE defect remains outside this non-IGNORE fix; existing IGNORE behavior and greedy controls are preserved.
) ## What type of PR is this? - [x] BUG ## Which issue(s) this PR fixes: Related to #31824. This PR addresses repeated-target **UPDATE IGNORE**; the non-IGNORE case was handled by #32821. ## What this PR does / why we need it: When an UPDATE IGNORE writes the same physical table through multiple aliases, an earlier alias may have already accepted or rejected a change. Checking a later candidate against the original snapshot alone can commit duplicate UNIQUE keys. A CHECK-rejected candidate can leave an accepted key unprotected if arbitration depends on the arrival order of concurrent UNION inputs. A later alias can also emit a false CHECK warning when it is validated against a snapshot value already changed by an accepted alias. - Use the preceding accepted row image for current key ownership, while carrying snapshot-key release evidence separately. - Reuse the existing HashBuild/DedupJoin path to prioritize current owners and reservations over competing claims independent of input arrival order. Preserve the auxiliary-row contract in parallel copies, remote codecs and spill/rebuild. - Report warnings only for rejected user candidates, not internal reservation/release rows. Update the stale warning expectation: the existing case has one real rejection, while a separate two-rejection control still reports two warnings. - Reuse generated-column dependency analysis to reject indirect changes to a protected repeated-target primary/partition key before writes. Preserve the existing non-IGNORE and single-target paths. - Build materialized ROW_NUMBER output directly in its owned result vector, eliminating a temporary scratch array without changing partitioning or output batches. - Group repeated-target candidates by physical row and apply priority inside the window. - Evaluate CHECK once per active repeated-table candidate on the preceding accepted row plus its assignments. Run DATALINK and hard child-FK admission afterward on the alias-local image. Keep composed FK rejection and UNIQUE arbitration on the candidate and retain the accepted row when the candidate is rejected. Design and invariants: [repeated-target UPDATE IGNORE arbitration](https://github.com/XuPeng-SH/matrixone/blob/edb0ae0ea609ffeea431ffc046dcc3804bea59a8/docs/design/20261117-update-ignore-unique-arbitration.md). ## Validation Follow-up head `fed4e5692c` is rebased on main `517e169538` and removes the now-unused early unique-check projections and consumed admission selectors. Rebased focused SQL race, full planner race (pre-rebase identical PR diff), formatting, vet, molint and incremental golangci-lint passed. The affected BVT passed twice after rebase: 352/352 per run. Additional SQL tests cover AUTO_INCREMENT, foreign-key success and rollback, CHECK rejection, same-alias competing keys and real covering index scans. An additional same-workload run checked every physical index key outside the timed statement. Follow-up df09bd2 corrects candidate grouping. A planner regression test fails before this change and passes after it; an operator-level test covers both input orders, NULL payload/priority, forced spill and resource cleanup. Focused SQL and planner/window race tests passed; the affected BVT passed twice at 352/352. A 10,000-row fanout experiment had comparable elapsed times before/after, including with a 64 KiB configured sort threshold; a separate operator test confirmed real spill. **CHECK feedback:** The regression raised in [review 5947330766](#32827 (review)) is fixed in c4a579b. SQL race tests verified both accepted aliases commit with zero warnings, a previous UNIQUE rejection leaves the expected CHECK violation, CHECK rejection precedes child FK validation, and missing alias-local parents still raise 1452 and roll back the full statement. A bad composed composite FK retains the previous accepted row. The affected BVT passed **355/355** twice. The two-session repeated-target test returned promptly with the parent key held, and the typed plan kept all four parent targets as row locks. The existing mixed-table timeout and six self-referential action outcomes were compared with df09bd2; the successful mixed overlap now reports one CHECK warning instead of two. On host 57, Linux/amd64, Go 1.27.1, verified CGo prerequisites, isolated two-CN fixture. Validation used PR head 531b319 and main edaafb6; the final rebase onto 59bf4b8 changed only unrelated mo-service connection-debug files and left the complete PR diff byte-for-byte identical: - Exact changed BVT case `update_multi_target_modern.sql`, normal mo-tester result comparison, twice on the same fresh instance: **352/352** statements passed each time. Checked that its test databases were absent between and after runs. - Focused public SQL tests for repeated-target arbitration, #31824/non-IGNORE controls and Unicode warnings passed, including focused `-race`. MySQL 8.0.46 independently returned one warning for the single real conflict and two for two independent conflicts. - Full owning-package `-race -short -tags matrixone_test` passed for HashBuild, DedupJoin, spill utilities, planner and compiler. The tests include resident, spill/re-spill and reservation-arrival-order cases, copy/serialization and protected-key guards. - Coverage-instrumented `TestUnicodeUniqueDiagnostics` passed on both CNs. Incremental formatting, vet, pinned molint and golangci-lint checks passed for the changed packages and relevant direct consumers. - Follow-up commit `b3a5465ce9`: full Window owning-package race, focused budget-boundary race, incremental vet, molint and golangci-lint passed. An independent 96 KiB budget control fails on 9557 because scratch and result are simultaneously charged and passes after this change; a 32 KiB denial still fails cleanly. - Same-host conflict witness: in a 500-row warmup the main base committed only 485 distinct UNIQUE keys; this PR preserved all 500. The PR also preserved all 2,000 keys in the larger tested cases, with matching count, distinct-count and sum from table and FORCE INDEX-hinted queries. Those nullable-key query plans were not checked for actual index access, so this is not an independent index-consistency proof. ## Performance and limits On host 57 with two CNs, a six-process interleaved comparison used latest main / pre-grouping PR / df09bd2 / df09bd2 / pre-grouping PR / latest main; one warmup and three measured updates per process. Pooled medians for repeated-target, no-conflict updates: | Rows / payload | Latest main 517e169 | Pre-grouping fed4e56 | Grouping fix df09bd2 | | --- | ---: | ---: | ---: | | 500 / narrow | 139.49 ms | 131.24 ms | 135.04 ms | | 500 / 512-byte | 154.30 ms | 146.97 ms | 148.52 ms | | 2,000 / narrow | 541.24 ms | 509.65 ms | 510.30 ms | | 2,000 / 512-byte | 603.26 ms | 579.17 ms | 570.91 ms | For 2,000 narrow, ranges were 527.2–564.6 / 501.1–516.1 / 504.6–548.8 ms. The small 500-wide single-target control was 6.24 / 5.78 / 6.49 ms, with overlapping ranges and occasional outliers; this does not rule out small-workload variation. Prior runs showed substantial shared-host outliers. These measurements are limited scenarios, not universal speedup or memory claims. Main conflict results were incorrect and are excluded. The original timed fixture's nullable-key hint did not prove physical index access. Separate same-SQL, same-size runs verified every key on both the pre-grouping PR and df09bd2 via a confirmed physical covering-index scan; rows, affected counts and warnings were checked independently. Plans show two obsolete Window/Partition pairs removed; this does not claim remaining small-batch materialization is fixed. Sparse updates against much larger indexes and per-query peak memory were not measured. With a CHECK constraint, a four-process df09/c4a/c4a/df09 comparison on the same host used one warmup and three measured statements per process. For 2,000 rows, repeated-target non-conflicting medians were **799.60 → 567.09 ms** (narrow) and **933.30 → 786.16 ms** (512-byte payload). Wide readings had outliers. Both arms verified rows, affected counts, warnings and physical covering-index keys. A separate forced-routing probe exposed existing behavior on **both** the main base and this PR: some repeated-target key updates hang with forced multi-CN routing; `forceOneCN=1,execType=3` with the coordinator removed from worker inventory can instead return success without writing. `execType=3` alone updated the rows but returned an incorrect affected-row count. These are not shown to be introduced by this PR; the forced-remote execution boundary remains unverified for the new auxiliary-row path. A separate self-referential FK control reproduced an existing limitation on latest main and this head: after certain ON UPDATE CASCADE / SET NULL actions, the base row changes but a physical covering UNIQUE-index scan can still return the old child key. Mixed non-overlapping self-cascade attempts also returned 1452 and rolled back on both revisions. These are not established as regressions from this PR and are not fixed here. CI for df09bd2 passed the required build, UT, SCA, coverage and multi-CN BVT jobs. Local planner and SQL race tests, vet, molint and incremental golangci-lint passed for the new patch. GitHub CI for c4a579b was pending at push.
What type of PR is this?
Which issue(s) this PR fixes:
issue #31824
What this PR does / why we need it:
A multi-target self-join
UPDATEcould commit duplicateUNIQUEvalues. After repeated physical targets were merged, the selector guarding deduplication keys was no longer valid, and independent per-alias checks could not detect two target rows writing the same new key.This change:
IGNORErepeated-target merge;UNIQUEchecks per physical table/index and evaluates the final merged row image;UPDATE IGNOREpath and per-row old-key self-update exemption;NULL, atomicity, index reads, and retry.Validation
Earlier author-reported validation (before the latest rebase):
./pkg/sql/planpackage;UPDATE IGNOREplan preservation;TestIssue31824SelfJoinMultiTargetUpdateUniqueandTestRepeatedAliasUpdateUsesOneConstraintSafePhysicalRow, including-count=3and-raceruns;GOWORK=off go build -mod=readonly ./pkg/sql/plan;GOWORK=off go vet -mod=readonly ./pkg/sql/plan ./pkg/tests/issues.A same-toolchain 1000-row non-conflicting benchmark (50 iterations x 3, Go 1.27.1 darwin/arm64, shared native artifacts) measured baseline
be781481at 80.59/84.38/85.16 ms and the fix at 70.05/71.26/72.08 ms per statement; median latency decreased by about 15.5%. A separate two-row benchmark was run-to-run noisy and is not used for a performance claim.Scope note
UPDATE IGNOREretains its existing pre-merge arbitration. A separate pre-existing same-new-keyUPDATE IGNOREduplicate-key problem was reproduced on both the base and this branch. RoutingIGNOREthrough the final merge was rejected because it regressedTestUpdateIgnoreRepeatedAliasesAdvanceGreedily; that separate issue is not addressed here.Rebase validation on 57
Rebased the two functional commits onto
mainat28ffd6ae. Added SQL cases for a one-to-many join and for atomic rollback when a repeated physical target is updated alongside a different table. On the clean base, the latter case succeeded when it should have returned duplicate-key error; on this branch both cases pass in normal and race modes. The shared-fixture test now registers database cleanup immediately after creation and reports cleanup errors.pkg/sql/planrace suite: 5,065 passing root tests, two skips, no failures. Focused planner and SQL regressions, including the existing repeated-alias control, passed; the SQL cases also passed without race.go vet, pinnedmolint check, and incremental golangci-lint passed for the planner, compile, frontend and issues-test packages.maincovered 1,000/5,000 narrow rows and 5,000/20,000 rows with a 512-byte payload, with and without a unique-key update. No consistent slowdown was observed; the wide-row timings were noisy. Fixture-inclusive peak RSS was approximately 616–620 MiB for narrow rows and 1,228–1,249 MiB for wide rows. Spill volume was not measured separately.update_multi_target_modern.sqlsuccessfully (309/309); this is pre-rebase evidence.The original-head UT failure was in
pkg/datasync/TestRequiredLsn, outside the UPDATE change. During Raft apply, a term lookup for index 14 saw a LogReader whose last index was 13 and propagated an error to the apply worker, causing a panic. The same test passed in an earlier run with identical relevant DataSync/LogService sources and passed 20 race repetitions locally on each of the old and rebased heads. Source ordering suggests an apply/reader-publication race, but this PR does not fix or conclusively prove that separate issue.CI for the rebased head is pending.