Repository navigation
fix(dml): preserve ordered ODKU semantics - #28265
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? |
LeftHandCold
left a comment
There was a problem hiding this comment.
Reviewed 29a0f02 against main/845fff8ee9cac962c5002a1007e0b0180efd591b, including the four linked issues, ordered assignment/action replay, logical versus physical row accounting, regular/irregular indexes, partition/direct/S3 writers, vector ownership, DDL cleanup and protocol propagation. Two concrete paths remain: scratch-vector ownership is lost when replay changes batch width, and moving no-op filtering downstream lets CHECK constraints reject a row image that must never be written. Details and minimal triggering inputs are inline.
Validation scope: these findings are established by tracing the production paths; the SQL snippets below are proposed regression cases, not claimed local server executions. The focused local dedupjoin test command stopped at the CGo prerequisite check (no matching libmo.dylib; primary-worktree native inputs differ), so I did not start a full rebuild or parallel UTs. Generated protobuf descriptor deltas were decoded and verified to contain exactly the declared new fields; diff --check passed. Existing author evidence and current CI were inspected; shared build/SCA/coverage are successful, with other UT/BVT jobs still pending at review time.
|
Revalidated the latest head |
|
Deep review update(正式 review 状态无法由 PR 作者自己设置为 REQUEST_CHANGES;以下结论已作为 comment 记录)。 结论仍是 不能 approve/merge。之前的 stable-vector ownership 和 pure-no-op CHECK 问题已关闭,但当前 head
当前 CI 和 |
|
Fixed the latest ODKU planner blocker and rebased onto current main in Root cause and invariant:
Regression and unhappy-path coverage:
Validation on the rebased exact head:
No CI result is claimed yet; this update does not wait for CI. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head 93a56046590b0239bdb7579e266f77184989c11a against main/cd096e20f04a51ad2975a868f013df83423e0c2a.
The earlier correctness blockers are closed: ordered/repeated assignment replay, per-action CHECK/FK/NOT NULL validation, historical-orphan FK eligibility, typed no-op equality, statement-local target arbitration, resolved-target locking, and distributed/S3 affected-row ownership all have coherent producer/consumer contracts on this head. I did not find another concrete correctness, leak, unbounded-retention, or wait-cycle bug in those paths.
I still cannot recommend merge because two acceptance blockers remain:
-
[P1 performance] Preserve the documented fast path when updated columns cannot affect a constraint.
bind_insert.go:2422-2423enablesEmitActionRowsfor any CHECK or enabled non-self FK on the table. It does not usepossiblyChangedColsto determine whether the ODKU assignment (including generated dependents) can change that constraint. The existing planner test atbind_upsert_affect_rows_test.go:210-221even locks in the slow path forsal = salalthough the FK tuple is unchanged.This is not just metadata overhead.
appendModernChildFkMarkOksbuilds/probes a parent MARK join for every emitted action before the eligibility guard is evaluated. Therefore a hot-key input with N duplicates and a wide payload, updating only a column unrelated toCHECK(pid > 0)/FOREIGN KEY(pid), expands from one final row per key to N wide action rows plus N FK probes. Replay batches bound peak memory, but they do not remove the multiplicative CPU/copy cost. It also contradicts the design contract at lines 138-140: “Tables whose ODKU targets cannot affect an action-level constraint retain the one-row-per-key-group fast path.” The four reported benchmarks do not include CHECK/FK/NOT NULL or a wide row, although the design requires both.Please make action emission constraint-sensitive: intersect updated/generated-dependent columns with each CHECK/FK dependency (NOT NULL is already assignment-sensitive), retain final validation where sufficient, and emit ordered actions only for constraints that can vary between actions. Add plan coverage for an unrelated-column update on CHECK/FK tables and report the constrained hot-key + wide-row evidence required by the design. If dependency pruning is intentionally deferred, the design/body and performance claim must be corrected and the worst-case cost quantified before acceptance.
-
[P1 regression coverage] Commit a deterministic test for the ALTER DROP INDEX lock-order fix.
The production change replaces nested
DROP TABLEwithdropIndexChildRelation, but this PR changes no DDL test.TestDropIndexChildRelationCleansLegacyPrivilegespredates this branch and tests only the helper's privilege cleanup; it never exercisesalterTableInplace, proves nested SQL is absent, or controls the DML/DDL lock ordering. Consequently reverting the critical call atddl.go:872torunSqlWithOptions("DROP TABLE ...")would leave all committed tests green. The manual ten-round race is probabilistic, while the design validation matrix explicitly claims a “deterministic barrier/fake-engine test” and says sleeps/probabilistic retries are not correctness oracles.Please add a deterministic regression that enters the ALTER DROP INDEX path with a fake engine/barrier, asserts parent-owned direct child deletion (and no recursive DDL acquisition), covers the error/rollback path, and demonstrates termination under the former conflicting lock order. Otherwise remove the unsupported validation claim, but for a hang/deadlock fix I consider the deterministic regression part of acceptance.
Non-blocking documentation point: the design says self-referencing FKs retain the existing post-execution statement-level path, whereas the PR body describes per-action FK validation without that exception. Record this limitation in the body so the supported semantic boundary is not overstated.
Validation boundary: git diff --check passes and the worktree is clean. I inspected current CI but did not wait for it. Local Go tests could not start in the isolated exact-head worktree because it has no matching cgo/libmo.dylib; the repository wrapper correctly rejected reusing the primary worktree's mismatched native artifact, so no local test pass is claimed here. Shared Build is successful; exact-head UT/SCA/coverage/BVT jobs were still running at review time.
GitHub does not allow a PR author to submit REQUEST_CHANGES on their own PR, so this is recorded as a COMMENTED review with a request-changes conclusion.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head e2caaa39da8080bfb74eb6d12b67dd7e954378f2 against base cd096e20f04a51ad2975a868f013df83423e0c2a.
Verdict: request changes. GitHub does not allow the PR author to submit REQUEST_CHANGES on their own PR, so this is recorded as a formal COMMENTED review with the equivalent blocking conclusion.
Historical findings
The earlier concrete findings are closed on this head:
- scratch-vector ownership across probe/finalize schema-width changes: the per-column stable pools are extended rather than replaced and are released by Reset/Free;
- pure ODKU no-op row-image restoration before CHECK/FK/index/RETURNING consumers;
- per-logical-action CHECK/FK/NOT NULL validation, typed no-op equality, and historical-existing orphan FK eligibility;
- statement-local target arbitration, constant-NULL target handling, resolved-target positioning/locking, and composite hidden-key identity domains;
- FK-disabled + CHECK/NOT NULL planning panic: FK eligibility production and consumption now use the same FK-enabled gate;
- the previous performance finding is addressed for isolated unrelated CHECK/FK updates: those plans retain compact one-row-per-key execution;
- the ALTER DROP INDEX lock-order change now has a deterministic fake-engine barrier/error-path regression and uses parent-owned direct child deletion;
- the PR body now states the self-referencing-FK boundary.
New blocker
[P1 correctness] A statement-local INSERT followed by UPDATE actions can bypass every unaffected CHECK/FK when another constraint enables action-row replay.
The new final-only CHECK marker is implemented as an ODKUForeignKeyCheck over the immutable primary key (bind_insert.go:3070-3085). For a new duplicate group, finalizeODKUActionRows emits the first INSERT action with all eligibility bits true but ActionFinal=false (dedupjoin/join.go:674-676). Each later action receives foreignKeyChanges(...); the synthetic PK does not change, so its bit is false (join.go:696-712). The planner then filters on ActionFinal before evaluating final-only CHECKs (bind_insert.go:3137-3146). Thus the only row carrying insert eligibility is discarded, while the retained final row is guarded out.
The same provenance loss affects an unrelated FK. The first INSERT action is not checked by odkuActionConstraintDef because that FK is unrelated to the UPDATE; the later final-image FK assertion sees a false tuple-change bit and skips it. This violates the required distinction between “an existing historical row whose tuple was unchanged” and “a row newly inserted by this statement whose tuple was unchanged by subsequent actions.”
Minimal CHECK counterexample:
create table t (
id int primary key,
pid int,
x int,
check (pid > 0),
check (x >= 0)
);
insert into t values (1, -1, 0), (1, 10, 1)
on duplicate key update x = values(x);The first row creates a new group with invalid pid; the second row conflicts and updates only x, which enables action replay through the affected check (x >= 0). The final row still has pid=-1 and must fail check (pid > 0), but the current eligibility flow skips it.
Equivalent FK counterexample:
create table p (id int primary key);
create table c (
id int primary key,
pid int,
x int,
check (x >= 0),
foreign key (pid) references p(id)
);
insert into c values (1, 999, 0), (1, 1, 1)
on duplicate key update x = values(x);The newly inserted group retains pid=999, so the statement must fail; current action-row provenance can guard the final FK check out.
The existing executor matrix misses this exact cross-product: its new-group action-row cases track an updated payload, while the new-group unchanged-key case uses compact execution. Please model group-origin INSERT eligibility separately from per-action tuple-change eligibility, then add regression coverage for new/existing × compact/action-row × single/multiple actions, with unaffected CHECK and FK, real/fake PK, and resumed batching. A fix must retain the fast path for unrelated constraints without skipping validation of newly inserted rows.
Other review dimensions
I re-audited the retained-vector ownership, resumable probe/finalize state, mailbox termination, S3 affected-row ownership transfer, v50/v51 serialization fences, optimizer ref/remap/deep-copy propagation, and direct DDL deletion/error paths. I found no additional concrete blocker in those paths. The branch is currently behind main; exact-head shared build, Ubuntu/x86 UT, SCA, coverage, and pessimistic BVT are green, while proxy BVT was still running at review time. I did not wait for CI or repeat previously completed 55-machine validation.
|
Fixed the final-insert constraint eligibility blocker in Root cause: action replay carried only per-action tuple changes. For a group created by this statement, an unchanged unrelated CHECK/FK was eligible on the initial INSERT action, but that row was removed by the final-action filter; the final row then carried The executor now keeps the two facts independent: intermediate actions use tuple-change eligibility, while the final row of a statement-created group retains insert-origin eligibility for every final-image constraint. This is applied consistently to the resumable and legacy finalize paths. Evidence:
CI was restarted by the push and is intentionally not being waited on. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review of exact head 98cbfbc91ccc88f55ae015e618cbf4ce366abc27 against merge base c1293102fd18908b59c4b049140aad67a50e0b16.
Verdict: no remaining code blocker found. This is my own PR, so GitHub cannot record an APPROVE review; this COMMENTED review is the author-side no-blocker conclusion and requests independent approval.
The last blocker from e2caaa39da is closed by 2e7d9adb54:
finalizeInsertConstraintEligibilityis reached only while finalizing unmatched groups, i.e. groups created by this statement. Both the resumable and legacy finalize implementations now make the final image eligible for every final-image constraint.- Intermediate actions still use tuple-change eligibility, so affected CHECK/FK/NOT NULL failures occur before the
ActionFinalfilter and cannot be folded away. - Existing-row probe/replay paths were not broadened: they retain tuple-change eligibility, so an unrelated update still does not revalidate a historical orphan FK.
- Single-action/compact groups preserve their original insert eligibility; multi-action and
DefaultBatchSize+1replay preserve first-action plus final-image eligibility. Real/fake/composite PK identity remains immutable for this marker. - The public CHECK and FK counterexamples now fail and roll back to zero rows; nearby controls prove that unapplied incoming columns do not create false violations.
Historical review map was reused and rechecked for interaction: ordered/repeated assignment replay, typed no-op equality, constraint-sensitive fast path, target arbitration/locking, stable vector ownership, bounded replay/arbitration state, WriteS3 affected-row transfer, protobuf fences, direct ALTER DROP INDEX ownership, and self-FK scope remain closed. The current design is consistent with the implementation and explicitly states the fast path, ownership, bounds, self-FK limitation, and deterministic validation contracts.
Unhappy-path closure for the new delta:
| Q | Result |
|---|---|
| Q1 cleanup ownership | PASS — no new resource owner; result rows and stable vectors retain the existing Reset/Free owner. |
| Q2 wait termination | PASS — no new wait/lock/channel/RPC edge; errors return through the existing operator cleanup path. |
| Q3 accumulation bound | PASS — the reused eligibility slice is bounded by constraint count, and action output remains bounded by batch/soft-byte limits. |
Evidence reused by semantic validity:
- exact business head
2e7d9adb54: focused UT plus clean 10.222.1.55 build and CHECK/FK black-box counterexamples, including cross-batch action replay and same-instance repetition; - exact merge head
98cbfbc91c: shared build, Ubuntu UT, SCA, coverage, proxy BVT, and pessimistic BVT all completed successfully; git diff --checkpasses and the review worktree is clean.
The branch is one commit behind current main@2da034110c; that commit is test-only publication/subscription coverage and does not intersect this PR. Rebase is still needed for delivery policy, but it does not invalidate the review conclusion. The remaining GitHub CHANGES_REQUESTED state is from an outdated thread that this series has addressed.
What changed
CLIENT_FOUND_ROWSare correct without forcing no-op storage/index rewrites.Prepare.ALTER TABLE ... DROP INDEXuse the parent-owned child-relation deletion path already used by standaloneDROP INDEX, removing the nested DDL lock-order inversion. Also remove the duplicate CDC task drop.Root cause
The planner reduced ODKU assignments into a map, which discarded statement order and duplicate targets. The executor then collapsed equal input keys before affected-row accounting, while a planner-level no-op filter removed the information needed for
CLIENT_FOUND_ROWS. Separately, ALTER DROP INDEX invoked nestedDROP TABLEafter acquiring parent/index locks, reversing the lock order used by concurrent index DML.The fix keeps three concepts independent:
Validation
go test ./pkg/sql/colexec/dedupjoin ./pkg/sql/colexec/multi_update ./pkg/sql/plan ./pkg/sql/compilego test -race ./pkg/sql/colexec/dedupjoin ./pkg/sql/colexec/multi_update -run 'ODKU|UpsertAffectRows|FilterODKU|PartitionContexts' -count=1make err-checkmake build(a,b)=(10,20)+a=a+1,b=a=>(11,11);a=a+1,a=a+1=>12;ROW_COUNT()=6, final value13;ROW_COUNT()=5, final value13;ROW_COUNT()=4, final value10;ROW_COUNT()=0; with a realclientFoundRows=trueconnection =>1;ON UPDATE timestamppreserves the implicit timestamp change, while a pure no-op leaves it unchanged;1;Performance, same machine, five-run median (
main-> this change):The differences are within run-to-run noise; no material regression was observed. Ordinary INSERT/UPDATE plans do not carry the two ODKU metadata columns.
make static-check-analysiscompleted its repositorygo vet/molint phase, but the local prebuiltgolangci-lintexecutable could not start because it embeds a stale absolute macOSlibmo.dylibpath. No code diagnostic was emitted before that tool-environment failure.Fixes #28177
Fixes #28178
Fixes #28180
Fixes #28181
Follow-up review and CI fixes
Review and failed-CI analysis at
55fcfdc3c6closed four additional paths:ON UPDATEand generated values from rejecting or mutating a row that will not be written; mixed no-op plus insert and genuine CHECK failure are covered.Follow-up validation:
make err-check;git diff --check.Found-rows BVT baseline follow-up (
c741845de2)The failed PROXY and pessimistic BVT jobs exposed stale expected
ROW_COUNT()values, not a storage-semantics regression. mo-tester negotiatesCLIENT_FOUND_ROWS: a duplicate that is a physical no-op contributes 1 logical affected row, and a mixed no-op duplicate plus one insert contributes 2. The BVT baselines and comments now reflect that client capability while retaining assertions that the row image, indexes, and implicitON UPDATEtimestamp do not change. The Coverage failure was downstream of the failed BVT coverage producers.Validation: exact failing statements were reconciled against both CI logs;
git diff --checkpasses. A fresh CI run is in progress on this commit.### Resolved-target lock and distributed S3 count closure (0576e740fbb)A final topology and concurrency review closed two P1 paths:
PreScopes. Each writer transfers one in-band count record to the finalUpdateFlushS3Infoowner. Direct, remote, multi-writer, partitioned, and all-physical-no-op paths share the same exact-once ownership rule; reset/error paths discard pending attempt state.Performance scope: ordinary INSERT/UPDATE and legacy affected-row protocols are unchanged. ODKU adds no per-row work beyond its existing weight accumulation and emits at most one five-column, payload-free control row per writer, with no extra S3 I/O.
Validation on the exact head:
mo-cgo-test -count=1 ./pkg/sql/colexec/multi_update— PASSmo-cgo-test -count=1 ./pkg/sql/plan— PASSmo-cgo-test -count=1 ./pkg/sql/compile— PASSmake err-checkandgit diff --check— PASSConstraint-sensitive ODKU and deterministic DDL closure (
e2caaa39da)The latest review blockers are closed systemically:
Name2ColIndexis absent.Additional test plan / evidence:
pkg/sql/plan,pkg/sql/colexec/dedupjoin,pkg/sql/compile— PASS0 issuesgit diff --check— PASSSelf-referencing FKs intentionally remain statement-level, as documented in the design; this change does not claim row-scoped self-FK validation.