Skip to content

[Bug]: DATA BRANCH cannot apply primary-key updates with ON UPDATE CASCADE #28026

Open

Description

@gouhongshen

Is there an existing issue for the same bug?

  • I searched open and closed DATA BRANCH issues; none covers primary-key update provenance with foreign-key ON UPDATE actions.

Branch Name

main

Commit ID

ad143902644719e65fa703df6397a011dc7d7dfa (PR #27996 head reviewed on 2026-09-02)

Other Environment Information

  • Local embedded single-CN / single-TN / single-Log test cluster
  • Parent table with an integer primary key and a referencing child foreign key using ON UPDATE CASCADE

Actual Behavior

A branch-side primary-key change is emitted as an independent delete of the old key plus an insert of the new key. DATA BRANCH MERGE and DATA BRANCH PICK replay that as DELETE/INSERT, so the parent-row delete fails with the foreign-key constraint error. An ordinary UPDATE on the same parent key succeeds and cascades to the child.

Expected Behavior

When a source update changes a referenced primary key, Data Branch apply should preserve it as one native destination UPDATE, allowing declared ON UPDATE CASCADE actions to run.

Steps to Reproduce

create database branch_pk_cascade;
use branch_pk_cascade;
create table parent_t (id int primary key, payload varchar(32));
create table child_t (id int primary key, parent_id int,
  constraint fk_child_parent foreign key (parent_id) references parent_t(id) on update cascade);
insert into parent_t values (2, 'two');
insert into child_t values (1, 2);

data branch create table merge_src from parent_t;
update merge_src set id = 3 where id = 2;
data branch merge merge_src into parent_t when conflict accept;

-- Control: update parent_t set id = 3 where id = 2; cascades child_t.parent_id.

The equivalent PICK setup (source and destination branches, keys(2)) fails for the same reason.

Root Cause and Scope

multi_update deletes the old row while writing the replacement without a durable operation identity. databranchutils.CollectChanges therefore exposes the old row ID/key as a tombstone and the replacement row ID/key as data. buildHashmapForTable and findDeleteAndUpdateBat correlate the two only by primary-key value; once the key changes, there is no safe association.

Matching rows by commit timestamp or iteration order would conflate independent delete/insert operations with updates and could trigger unintended cascades, so it is not a safe fix. This needs an explicit old-to-new update provenance link through the change stream, followed by native UPDATE apply and MERGE/PICK regressions for cascade, non-cascade rejection, and atomicity.

Related

Activity

  1. added
    kind/bug
    on Sep 2, 2026
  2. self-assigned this
    on Sep 2, 2026
  3. added
    severity/s0
    ai-easy
    and removed on Sep 2, 2026
  4. gouhongshen commented on Sep 2, 2026

    @gouhongshen
    ContributorAuthor

    I investigated this on the issue's stated baseline, PR #27996 head ad143902644719e65fa703df6397a011dc7d7dfa, using a fresh embedded single-CN/single-TN/single-Log instance built from that exact commit. I am deferring this issue rather than opening a PR because the required fix is a persistent change-stream protocol decision, and no safe local implementation exists on the current contract.

    Reproduction and executable-test attempt

    I constructed a self-contained 82-line BVT draft covering four distinct semantic cells:

    1. MERGE of a real primary-key UPDATE 2 -> 3 into a parent referenced by ON UPDATE CASCADE.
    2. PICK of the old key keys(2) for the same primary-key update, with the PICK destination referenced by ON UPDATE CASCADE.
    3. The corresponding non-cascade/RESTRICT rejection and post-error parent/child state (failure atomicity).
    4. A counterexample in which DELETE id=2 and INSERT id=3 are independent statements in one source transaction. This must not acquire UPDATE semantics.

    Observed results on ad14390264:

    • MERGE and PICK both returned ERROR 20101 ... Cannot delete or update a parent row: a foreign key constraint fails.
    • After each failed apply, the parent remained id=2 and the child remained parent_id=2, proving statement atomicity on the current failing path.
    • The ordinary control UPDATE parent_t SET id=3 WHERE id=2 succeeded and changed the child to parent_id=3, proving that native UPDATE supplies the required FK action.
    • The RESTRICT case rejected and retained both original rows.
    • The independent same-transaction DELETE/INSERT counterexample produced the same FK rejection and retained both original rows. Therefore commit timestamp, transaction identity, and iteration adjacency cannot safely distinguish it from a primary-key update.
    • DATA BRANCH DIFF exposes the primary-key update exactly as DELETE id=2 plus INSERT id=3.

    I did not add this draft under test/distributed/cases: there is no correct post-fix result to assert until the protocol below is selected and implemented. Adding a skipped/issue-tagged test would not satisfy the executable-proof requirement.

    Proven root cause and ownership boundary

    • multi_update.updateOneBatch calls the relation delete path and then the insert path; no operation identity is passed between them.
    • disttae.Transaction.writeBatchWithAutoIncrEpochKnown generates a fresh physical RowID for each insert, so the replacement cannot be associated by RowID with the deleted row.
    • engine.ChangesHandle.Next can return only a data batch and a tombstone batch. It has no update/provenance channel.
    • TAE logtail construction emits delete and insert batches independently. Persisted tombstones contain deleted RowID, PK, and commit timestamp; they contain no replacement identity.
    • Although api.Entry_Update exists as an enum value, repository search finds no TN/logtail/checkpoint/replay implementation that consumes it as a durable row update.
    • Data Branch consequently receives old-key tombstone 2 and new-key data 3. The existing hash reconciliation is keyed by PK and cannot pair them after the PK changes.

    This also explains why a frontend-only patch is unsafe. Pairing by commit TS, transaction, or stream order would misclassify semantic cell 4 and could run ON UPDATE CASCADE for an independent delete/insert. Reusing the old RowID is not viable because RowID is the physical address assigned to the new append. Carrying only an in-memory marker would fail after checkpoint/recovery, which is inside the supported Data Branch range lifecycle.

    Required decision before implementation

    A complete fix must choose and specify one durable representation, for example either:

    • an update record that carries an explicit old-to-new identity through CN workspace writes, TN application, logtail, objects/checkpoints, replay, and CollectChanges; or
    • a separately persisted provenance log with retention/GC tied to the Data Branch lineage window.

    That decision must also define mixed-version behavior and the contract for the other CollectChanges consumers (table_changes, CDC, ISCP, and publication), plus checkpoint/compaction/restart preservation and bounded GC. These are storage/protocol compatibility choices, not implementation details I can safely infer in a bug-fix PR.

    There is also a delivery dependency: the issue's stated baseline is the still-open #27996. Current main does not contain its native stable-key UPDATE apply path. Copying #27996's four commits into a #28026 PR would duplicate and expand this issue's scope to #27992 rather than produce a focused change.

    Decision

    Excluded from a PR and deferred pending an approved persistent update-provenance design and the disposition of #27996. No source files were changed and no PR was opened.

  5. added and removed
    severity/s0
    on Sep 2, 2026
  6. gouhongshen commented on Sep 4, 2026

    @gouhongshen
    ContributorAuthor

    Automated AI triage

    This issue requires human involvement and cannot currently be completed independently by the
    automated fix loop.

    Reason

    Storage, transaction, and Data Branch owners must approve a versioned durable update-provenance contract. The current repository design gate requires an approved design before implementation when persistent/distributed contracts change; no applicable approved design was found.

    Evidence

    Current MULTI_UPDATE emits separate delete/insert writes; ChangesHandle exports data and tombstones, and Data Branch associates replacements by primary key. A key move loses the association. Independent DELETE/INSERT is an explicit counterexample to frontend heuristics, so a focused frontend patch cannot prove correctness.

    Please use this analysis to provide the missing decision, environment, evidence, or ownership
    needed before the issue is returned to the AI candidate pool.

  7. added
    severity/s0
    and removed on Sep 4, 2026
  8. gouhongshen commented on Sep 4, 2026

    @gouhongshen
    ContributorAuthor

    Triage decision: defer.

    Current-main verification (99ed717, fresh embedded single-CN/single-TN/single-Log instance):

    • The exact MERGE primary-key move 2 -> 3 with ON UPDATE CASCADE still fails with ERROR 20101. DATA BRANCH DIFF reports DELETE 2 plus INSERT 3. After the error, parent id=2 and child parent_id=2 remain, proving statement atomicity.
    • The equivalent PICK from sibling branches with keys(2) and ON UPDATE CASCADE fails identically and leaves both destination rows unchanged.
    • A native UPDATE parent_t SET id=3 WHERE id=2 succeeds and changes child.parent_id to 3, proving the FK implementation already has the required native-update behavior.
    • With the default RESTRICT action, both Data Branch apply and native UPDATE reject the key move and retain parent id=2 plus child parent_id=2.
    • Counterexample: DELETE id=2 and INSERT id=3 executed as two independent statements in one source transaction produce the same DELETE 2 plus INSERT 3 change stream. Applying them correctly retains DELETE semantics and fails against the referencing child. Therefore commit timestamp, transaction identity, or iteration adjacency cannot safely infer update provenance.

    Root cause on current main:

    • multi_update.updateOneBatch invokes Relation.Delete and Relation.Write separately.
    • disttae generates a new physical RowID for the replacement insert.
    • The CN precommit protocol serializes user DML only as api.Entry_Insert or api.Entry_Delete. api.Entry_Update is declared but has no TN HandleWrite, logtail, partition-state, checkpoint, or CollectChanges implementation.
    • engine.ChangesHandle exposes only data and tombstone batches, and Data Branch reconciliation keys them by PK. Once the PK changes, no durable old-to-new association remains.

    A frontend pairing patch would silently convert the independent DELETE/INSERT counterexample into UPDATE semantics and could trigger unintended ON UPDATE actions. An in-memory marker would also be lost across logtail/checkpoint/recovery. The narrowest correct fix therefore requires an approved persistent update-provenance contract spanning CN workspace writes, TN/WAL, logtail, checkpoints/replay, and ChangesHandle, including mixed-version behavior, retention/GC, and semantics for table_changes, CDC, ISCP, publication, MERGE, and PICK.

    The prior dependency on #27996 is now resolved because that PR is merged; the protocol/design blocker remains. I attempted the complete public-path regression matrix above, but no passing UT/BVT can be committed until that contract is selected and implemented. A skipped case would not be executable proof.

    To promote later: storage/Data Branch owners approve the durable old/new identity representation and compatibility/retention contract. At that point the implementation must include MERGE and PICK cascade success, RESTRICT rejection, independent DELETE/INSERT non-conflation, restart/checkpoint preservation, and failure atomicity tests.

  9. 376 remaining items

  10. gouhongshen commented on Sep 8, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated this assignment at f72ca9efbeb3a7c673701e4a135cc6670c33cfde: fresh origin/main, HEAD and merge-base are identical, and the worktree is clean. The group contains only this issue. #27996 is merged; its stable-key fix does not supply primary-key-move provenance.

    The full root-cause analysis, attempted executable proof, and stopping criteria in #28026 (comment) remain applicable. I inspected the retained diagnostic_test.go and diagnostic.log for this exact head: the native, MERGE, PICK keys(2), RESTRICT, and independent same-transaction DELETE/INSERT subtests all completed (package 17.313s). This is reused diagnostic evidence, not a new run or proof of a fix. Native UPDATE cascades; MERGE/PICK reject the real key move; rejected operations preserve parent/child rows. The independent DELETE/INSERT counterexample correctly rejects. Existing stable-key MERGE/PICK BVT cases cannot prove this issue fixed.

    Source reinspection confirms that multi_update.updateOneBatch deletes then inserts, ChangesHandle.Next exposes data/tombstone batches without an update association, and branch reconciliation probes by the old PK. Thus pairing the two records heuristically would change independent DELETE/INSERT semantics. A successful regression requires durable old-to-new identity across storage/replay and branch collection, including PICK selection; an output-helper unit test with a supplied update marker cannot establish it.

    No approved versioned provenance design was found in the branch design documents or issue-related PR search. The mo-dev design gate requires an approved design for the persistent/wire and cross-owner contract expansion. Storage/Data Branch owners must decide representation, historical/mixed-version behavior, checkpoint/restart preservation, retention bounds, and update-chain/PICK semantics before implementation. Acceptance must cover MERGE/PICK cascade success, RESTRICT and failure atomicity, independent-operation non-conflation, selection boundaries, and persistence.

    Per the authorized comment-and-defer path, exclude the sole issue from implementation delivery and replace severity/s0 with deferred. No workaround, source/test change, commit, push, or Draft PR is made. The missing protocol decision, rather than local build capability, is the blocker.

  11. gouhongshen commented on Sep 8, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated this sole-issue assignment. Worktree HEAD is f72ca9efbeb3a7c673701e4a135cc6670c33cfde and clean; freshly fetched main is now 52f5204603946880a9c2cab19a9371bdceca2ac1. The intervening changes concern object search and PK conflict-check cancellation; they do not introduce update provenance. I do not claim a runtime test on the newer main.

    I inspected the retained exact-worktree-head diagnostic_test.go and terminal diagnostic.log (embedded cluster, TestIssue28026Diagnostic, five selected subtests; package completed in 17.313s). This reuses existing diagnostic evidence, not a new execution or fixed-success proof. Native UPDATE cascades 2 -> 3. Exact MERGE and sibling-branch PICK keys(2) reject with ERROR 20101 and preserve parent/child rows. RESTRICT rejects atomically. Independent DELETE/INSERT in one transaction also rejects correctly. The test explicitly checks destination and child contents after each action. The full investigation and attempted executable proof remain at #28026 (comment) . Existing MERGE/PICK foreign-key BVTs change payload with stable keys and cannot prove this issue fixed.

    Source reinspection confirms separate delete/insert calls in multi_update.updateOneBatch, data/tombstone-only ChangesHandle.Next, and old-PK lookup in findDeleteAndUpdateBat. A real key move must retain an explicit durable old-to-new association; transaction/timestamp/order matching cannot distinguish the independent-operation counterexample. PICK additionally needs to follow that association from the selected old key. A local output test supplying an update marker would bypass the missing producer contract.

    No approved provenance design was found in repository design documents or issue-related PR search (which returns merged #27996, explicitly excluding this issue). The required change expands persistent/wire contracts across SQL/CN, storage/recovery and change-stream consumers, triggering mo-dev G-FEATURE-DESIGN. Storage/Data Branch owners must approve representation, atomic publication, update chains/key reuse and PICK semantics, historical/mixed-version behavior, checkpoint/compaction/restart preservation, retention bounds and consumer compatibility. This is the precise stopping reason; there is no safe local patch or successful regression to deliver before that decision.

    Per the requested comment-and-defer path, exclude #28026 from a PR and replace severity/s0 with deferred. Required eventual proof includes MERGE/PICK cascade success, native control, RESTRICT, failure atomicity, independent-operation non-conflation, key-selection boundaries and persistence/restart. No source changes, commit, push or Draft PR are made.

  12. gouhongshen commented on Sep 8, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated #28026 at freshly fetched HEAD = origin/main = merge-base = ffabe501da007d526544192e1c280cf0ce2c7022; the worktree is clean. This group contains one coherent issue: MERGE and PICK lose the same primary-key-update provenance.

    I read CONTRIBUTING.md, the PR template, the nearby producer/collector/reconciliation code, existing MERGE/PICK foreign-key BVTs, and the retained diagnostic source and terminal log from f72ca9efbeb3a7c673701e4a135cc6670c33cfde. That diagnostic selected all five subtests and completed in 17.313s: native UPDATE cascaded 2 -> 3; MERGE and sibling-branch PICK keys(2) failed with the FK error while preserving destination parent/child contents; RESTRICT MERGE rejected atomically; independent DELETE 2 and INSERT 3 in one transaction also correctly rejected. All four branch DIFF outputs were DELETE 2 plus INSERT 3. This is inspected historical diagnostic evidence, not a new runtime run at ffabe50 or proof of a fix. Full test construction, command, findings and evidence are recorded in #28026 (comment) .

    Current-source proof remains:

    • multi_update.updateOneBatch calls delete_table then insert_main_table, without transferring an old-to-new operation identity.
    • disttae/tools.go serializes the writes as separate insert/delete entries.
    • ChangesHandle.Next returns data/tombstone batches, and BranchChangeHandle forwards them without update association.
    • findDeleteAndUpdateBat looks up replacement data by the deleted PK. PICK filters membership upstream, so selecting old key 2 cannot follow an unlinked replacement at 3.
      These inspected producer/collector/reconciliation files have no changes since the retained diagnostic revision. Existing FK BVT cases update payloads with stable keys; they cannot establish this issue's key-move behavior.

    A successful public-path regression cannot be constructed by supplying an update marker only in an output-helper test: that bypasses the missing producer/persistence contract. Pairing by timestamp, transaction, values or order conflates the independent DELETE/INSERT counterexample with UPDATE and could run unintended cascades. An in-memory association does not survive recovery. No such workaround was added.

    The required fix expands persistent/wire contracts across SQL/CN writes, storage/recovery and change-stream consumers. Repository design searches and the issue-related PR search found no approved versioned provenance design (the PR search returned merged #27996). The mo-dev design-first gate therefore blocks implementation delivery. Storage/Data Branch owners must approve durable identity representation and atomic publication, update chains/key reuse, PICK selection, historical/mixed-version behavior, checkpoint/compaction/restart preservation, retention/GC bounds, consumer compatibility and hot-path cost. This missing architectural decision is the precise stopping reason.

    Acceptance after design approval must include the exact MERGE and PICK CASCADE cases, native control, RESTRICT rejection, failure atomicity, independent-operation non-conflation, key-selection boundaries and persistence/restart. No fixed-success UT/BVT is claimed. Per the authorized all-members-deferred path, exclude this sole issue from PR delivery and replace severity/s0 with deferred. No source/test changes, commit, push or Draft PR are made.

  13. gouhongshen commented on Sep 8, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated this assignment at freshly fetched HEAD = origin/main = ffabe501da007d526544192e1c280cf0ce2c7022, with a clean worktree. MERGE and PICK are one coherent provenance problem. No new approved design or implementation was found; issue-related PR search returns merged #27996.

    I inspected the retained TestIssue28026Diagnostic source and terminal log from f72ca9efbeb3a7c673701e4a135cc6670c33cfde: all five diagnostic subtests completed, package duration 17.313s. Native UPDATE cascaded 2 -> 3; exact MERGE and sibling PICK keys(2) rejected with the foreign-key error and preserved parent/child rows; RESTRICT rejected atomically; independent DELETE/INSERT in one transaction rejected as required. These are historical diagnostic results, not a new run or fixed-success proof. The full investigation and attempted executable test construction are recorded in #28026 (comment) and the previous current-main analysis in #28026 (comment) .

    Current source still calls delete_table then insert_main_table in multi_update.updateOneBatch, exposes data/tombstone batches through ChangesHandle.Next, and reconciles tombstones using their encoded key in findDeleteAndUpdateBat. Inspected producer/frontend/collector files have no diff from the retained diagnostic revision. A moved key has no durable old-to-new association. Timestamp, transaction, order or value matching would conflate the independent-operation counterexample; an output-helper test with invented provenance would bypass the missing producer contract.

    Stopping reason: a safe fix requires an approved persistent provenance contract across SQL/CN, storage/recovery and change-stream consumers. The mo-dev design-first gate requires approval before implementing this architectural expansion. Owners must decide representation and atomic publication, update chains/key reuse and PICK selection, historical/mixed-version semantics, checkpoint/compaction/restart preservation, retention/GC bounds and consumer compatibility. Standing implementation permission does not supply those unresolved semantics. Required eventual executable proof includes MERGE/PICK cascade success, native control, RESTRICT and atomicity, independent-operation non-conflation, selection boundaries and restart persistence.

    Following the authorized all-members-deferred path: exclude this sole issue from PR delivery and replace severity/s0 with deferred. No production/test changes, commit, push or Draft PR; no claim that the bug is fixed.

  14. gouhongshen commented on Sep 8, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated the assignment at freshly fetched HEAD = origin/main = merge-base = b2f0f3fe69b23cde495c59d226c647aba555cfdc, with a clean worktree. The sole assigned issue is coherent: MERGE and PICK lose the same primary-key-update association.

    Current-source investigation confirms multi_update.updateOneBatch calls delete_table followed by insert_main_table; disttae serializes separate insert/delete entries; ChangesHandle.Next and BranchChangeHandle expose data/tombstone batches without an old-to-new update link. findDeleteAndUpdateBat matches replacement data by the deleted primary key using PopByVectorsStream. PICK also filters keys upstream. A move from 2 to 3 cannot be reconstructed safely from this representation.

    I read the contribution rules, PR template, existing MERGE/PICK FK BVTs, and retained executable diagnostic source and terminal log at revision f72ca9efbeb3a7c673701e4a135cc6670c33cfde. That test selected five subtests and completed in 17.313s: native UPDATE cascaded; exact MERGE and sibling PICK keys(2) rejected while retaining parent/child state; RESTRICT MERGE rejected atomically; independent DELETE/INSERT in one source transaction also rejected. Public DIFF emitted DELETE 2 plus INSERT 3 for both real UPDATE and independent operations. The full test construction and command are recorded in #28026 (comment) . This is inspected historical diagnostic evidence, not a fresh runtime run at b2f0f3f and not proof of a fix. The inspected producer, serialization, collector, replay and frontend files have no diff from that diagnostic revision.

    Existing FK BVTs cover stable-key payload changes. A helper test supplied with invented update provenance cannot prove the missing public producer contract. Timestamp, transaction, order or value pairing would conflate the independent-operation counterexample and could trigger unintended cascades; an in-memory association would not establish recovery correctness. No workaround was added.

    Stopping reason: the clean solution expands durable/wire contracts across SQL/CN, storage/recovery and change-stream consumers. The mo-dev design-first gate requires an approved versioned design for that architectural expansion. Repository design searches and the issue-related PR search found no approved provenance design; the PR search returns merged #27996, which explicitly excludes this issue. Storage/Data Branch owners must approve identity representation and atomic publication, update chains/key reuse, PICK selection, historical/mixed-version behavior, checkpoint/compaction/restart preservation, retention/GC bounds, consumer compatibility and hot-path costs before implementation.

    Required eventual executable proof: exact MERGE/PICK cascade success, native UPDATE control, RESTRICT rejection, failure atomicity, independent DELETE/INSERT non-conflation, key-selection boundaries and persistence/restart preservation. No fixed-success UT/BVT is claimed. Following the authorized all-members-deferred path, exclude #28026 from PR delivery and replace severity/s0 with deferred. No source changes, commit, push or Draft PR.

  15. gouhongshen commented on Sep 8, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated this assignment against freshly fetched HEAD = origin/main = merge-base = b2f0f3fe69b23cde495c59d226c647aba555cfdc; worktree is clean. The design blocker remains, so this sole group member is excluded from PR delivery and deferred.

    I inspected contribution rules, PR template, current producer/collector/reconciliation code, existing MERGE/PICK foreign-key BVTs, and the retained TestIssue28026Diagnostic source and terminal log. Full investigation and test construction: #28026 (comment) . The five diagnostic scenarios at f72ca9efbe passed in 17.313s: native UPDATE cascades; exact MERGE and sibling PICK keys(2) fail with unchanged destination parent/child; RESTRICT rejects atomically; independent DELETE/INSERT in one transaction also rejects. These are historical diagnostic results, not a fresh runtime run or proof of a fix.

    There is no diff from that diagnostic revision in multi_update, disttae transaction writing, TAE logtail handling, logtail replay partition state, engine change-handle types, BranchChangeHandle, or frontend hashdiff. Current code still deletes then inserts without a durable association, exposes data/tombstone batches, and reconciles by the deleted primary key. Existing FK BVTs test stable-key payload updates. Thus a fabricated helper input cannot prove the missing source-to-apply contract, and timestamp/transaction/order/value pairing would conflate independent operations with UPDATE.

    No approved update-provenance design was found in repository design/RFC searches or the issue-related PR search; merged #27996 explicitly excludes this issue. A clean solution changes persistence/wire and cross-owner contracts, triggering .agents/skills/mo-dev/references/feature-design-review.md: “Require a design when ... changes a public API, client/server or wire protocol, catalog or on-disk format, persistent state ...”. Its required artifact is an approved versioned design before implementation. Storage/Data Branch owners must settle durable identity and atomic publication, chains/key reuse, PICK key selection, historical/mixed-version behavior, checkpoint/compaction/restart preservation, consumer compatibility, retention/GC bounds and hot-path costs.

    Stopping reason is this unresolved architectural decision, not unavailable test infrastructure. Required eventual proof remains exact MERGE/PICK cascade success, native control, RESTRICT and failure atomicity, independent-operation non-conflation, selection boundaries and persistence/restart. No workaround, production changes, commit, push or Draft PR; restoring deferred in place of severity/s0 under the authorized all-members-deferred path.

  16. gouhongshen commented on Sep 8, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated this sole-issue assignment at freshly fetched HEAD = origin/main = merge-base = b2f0f3fe69b23cde495c59d226c647aba555cfdc; worktree is clean. The full investigation and executable diagnostic construction remain documented in #28026 (comment) . No implementation is ready for a PR.

    I reread CONTRIBUTING.md, the PR template, current producer/change-handle/reconciliation code, existing MERGE/PICK FK BVTs, and the retained diagnostic source and terminal log. The historical TestIssue28026Diagnostic run at f72ca9efbe selected five scenarios and completed in 17.313s: native UPDATE cascades 2 -> 3; exact MERGE and sibling PICK keys(2) fail with the FK error and preserve destination parent/child rows; RESTRICT rejects atomically; independent DELETE/INSERT in one transaction also rejects. This is inspected historical diagnostic evidence, not a fresh test run or fixed-success proof. The producer, disttae transaction serialization, TAE logtail/replay, engine change-handle interface, BranchChangeHandle and frontend hashdiff paths inspected have no diff from that diagnostic revision.

    The current root cause remains: multi_update.updateOneBatch deletes then inserts; ChangesHandle.Next exposes data/tombstone batches without a semantic update association; findDeleteAndUpdateBat probes replacement rows using the deleted primary key. PICK filters membership upstream. A real key move and independent DELETE/INSERT cannot safely be distinguished by timestamps, transaction membership, order or values. Existing stable-key FK BVTs and a helper supplied with invented update provenance cannot prove the missing public producer-to-apply contract. No heuristic workaround was implemented.

    Repository design/RFC searches and the issue-related PR search found no approved provenance design; the latter returns merged #27996, which explicitly excludes this issue. The clean solution expands persistence/wire and cross-owner contracts. The mo-dev design gate requires an approved versioned design before implementing that expansion. Storage/Data Branch owners must settle durable identity and atomic publication, update chains/key reuse, PICK selection, historical and mixed-version behavior, checkpoint/compaction/restart preservation, retention bounds, consumer compatibility and hot-path cost. These unresolved architectural semantics are the precise stopping reason, not unavailable test infrastructure.

    Required eventual proof remains exact MERGE/PICK CASCADE success, native UPDATE control, non-cascade rejection and failure atomicity, independent-operation non-conflation, key-selection boundaries and persistence/restart. No fixed-success UT/BVT is claimed. Under the authorized all-members-deferred path, exclude this sole issue from PR delivery and replace severity/s0 with deferred. No source/test changes, commit, push or Draft PR.

  17. gouhongshen commented on Sep 9, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated on current main at af965c3e4d86ec218de05b585dbafbedb10aa1ae in a fresh embedded single-CN/single-TN/single-Log test instance.

    I constructed and ran a temporary self-contained SQL probe through pkg/tests/dml (then removed it, so the worktree remains source-clean):

    • Native UPDATE parent_t SET id = 4 WHERE id = 2 with a child FK ON UPDATE CASCADE succeeds and changes child_t.parent_id to 4.
    • The exact issue MERGE (merge_src: 2 -> 3, WHEN CONFLICT ACCEPT) returns the foreign-key error. Parent and child remain 2, proving the current failure is atomic.
    • The equivalent sibling-branch PICK (pick_src: 2 -> 3, PICK ... KEYS(2) WHEN CONFLICT ACCEPT) returns the same error and retains the destination parent and child at 2.

    Command: .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s -run ^TestDataBranchPrimaryKeyUpdateForeignKeyProbe$ ./pkg/tests/dml; selected test passed in 14.345s because it asserts those pre-fix failures and their post-error state.

    Current ownership analysis confirms this is not safely fixable in frontend apply code: multi_update.updateOneBatch invokes delete then insert, ChangesHandle.Next exposes only independent data and tombstone batches, and findDeleteAndUpdateBat can reconcile them only by the deleted primary key. A move 2 -> 3 therefore loses association. Pairing by timestamp, transaction, or order would conflate an independent DELETE 2 plus INSERT 3 with UPDATE and could incorrectly execute ON UPDATE actions. An in-memory association would not survive the supported checkpoint/recovery path.

    The narrowest correct closure is a persistent cross-boundary update-provenance protocol spanning SQL/CN writes, TN/WAL, logtail, checkpoint/replay, and every CollectChanges consumer. This changes persistent/wire and distributed recovery contracts, so the design gate requires an approved versioned design. No such design selects the durable old-to-new identity, atomic publication, PICK old-key selection behavior, retention/GC, mixed-version, or restart semantics.

    I therefore exclude this sole issue from PR delivery and defer it rather than invent an unsafe correlation workaround. Eventual proof must cover MERGE/PICK cascade success, RESTRICT rejection and failure atomicity, independent DELETE/INSERT non-conflation, old-key PICK selection, and checkpoint/restart preservation. No source/test changes, commit, push, or Draft PR were made.

  18. gouhongshen commented on Sep 9, 2026

    @gouhongshen
    ContributorAuthor

    Deferred after revalidating the sole assigned member at HEAD = origin/main = f0c31cd4b830be32442cf329e0a3fb08aa9c16c3. The immediately preceding fresh embedded-cluster probe at af965c3e4d established the exact MERGE and sibling PICK keys(2) failures, atomic destination state, and native ON UPDATE CASCADE control. The current-head range changes no relevant path: git diff af965c3e..HEAD -- pkg/sql/colexec/multi_update pkg/vm/engine/disttae pkg/vm/engine/tae pkg/vm/engine/change_handle.go pkg/frontend/data_branch* pkg/frontend/databranchutils pkg/cdc pkg/iscp pkg/publication test/distributed/cases/git4data/branch is empty.

    Current audit still finds delete-then-insert production, data/tombstone-only change handles, and PK-keyed reconciliation. A real key move and an independent DELETE/INSERT cannot be distinguished by timestamp, transaction, order, or value; doing so would spuriously apply FK ON UPDATE actions. The required durable provenance change crosses CN/TN/WAL, logtail, checkpoint/recovery, and all CollectChanges consumers. No approved versioned design exists, and the repository design gate blocks such a persistent/distributed protocol change.

    The prior full reproduction/test-construction record remains valid: #28026 (comment). The issue has been set to deferred (replacing severity/s0). No source change, commit, push, or Draft PR is appropriate. Reactivation requires an approved provenance/compatibility design, then executable MERGE/PICK CASCADE, RESTRICT/atomicity, independent-operation non-conflation, and checkpoint/restart proof.

  19. gouhongshen commented on Sep 9, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated the sole assigned member at HEAD = origin/main = f0c31cd; the worktree is clean. MERGE and PICK remain one coherent missing-provenance problem.

    Fresh reproduction and test construction:

    • Built the repository CGo artifacts with make cgo, then ran .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s -run ^TestDataBranchPrimaryKeyUpdateForeignKeyProbe$ ./pkg/tests/dml.
    • The temporary, self-contained embedded-cluster probe passed in 16.264s because it asserts the current defect, then it was removed. Native UPDATE 2 -> 3 with ON UPDATE CASCADE updated both parent and child. The exact MERGE and sibling PICK keys(2) both returned a foreign-key error and left parent and child at 2, proving atomic failure. An independent DELETE 2 plus INSERT 3 in one source transaction also retained DELETE semantics and failed atomically.

    Current source confirms why a frontend-only fix is unsafe. multi_update.updateOneBatch deletes before inserting the replacement. engine.ChangesHandle.Next exposes separate data and tombstone batches; BranchChangeHandle forwards them unchanged. findDeleteAndUpdateBat reconstructs an LCA row for a tombstone and probes replacement data by that deleted primary key. A move 2 -> 3 has no association, while an independent DELETE 2 plus INSERT 3 has the same available shape. Timestamp, transaction, order, or value matching would conflate them and could execute unintended ON UPDATE actions.

    Existing merge_foreign_key_update and pick_foreign_key_update BVTs cover stable-key payload updates only. A frontend helper supplied with invented provenance would bypass the missing producer-to-consumer contract, so no unsound workaround or non-proving regression was added.

    The narrowest correct closure changes persistent/wire and distributed recovery contracts across SQL/CN writes, storage/WAL, logtail/checkpoint replay, and CollectChanges consumers. This triggers the repository design gate. Repository docs/design searches and GitHub PR search found no approved, versioned update-provenance design; the only related PR is merged #27996, whose stated scope explicitly excludes primary-key moves. Required decisions include durable old-to-new identity and atomic publication, update chains/key reuse, PICK old-key selection, checkpoint/restart and mixed-version behavior, retention/GC bounds, consumer compatibility, and hot-path cost.

    Stopping reason: the mandatory design is absent, not lack of reproduction or test infrastructure. After an approved design, acceptance evidence must cover MERGE/PICK CASCADE success, native control, RESTRICT rejection and atomicity, independent-operation non-conflation, old-key selection boundaries, and checkpoint/restart persistence. This issue is excluded from PR delivery; no source change, commit, push, or Draft PR is appropriate.

  20. gouhongshen commented on Sep 9, 2026

    @gouhongshen
    ContributorAuthor

    Revalidated the sole assigned member at HEAD = origin/main = e8ae1e51f2b0f04b6d69d37ff6ccf8166736c9e6. The worktree is clean, and the f0c31cd4..HEAD range contains no change in the Data Branch, MULTI_UPDATE, change-handle, storage/replay, or branch BVT paths.

    Fresh reproduction used a temporary, self-contained embedded single-CN/single-TN/single-Log probe, then removed it. Command: .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=240s -run ^TestDataBranchPrimaryKeyUpdateForeignKeyProbe$ ./pkg/tests/dml; it selected five named scenarios and passed in 15.660s because it asserts current behavior:

    • Native UPDATE parent SET id = 3 WHERE id = 2 with ON UPDATE CASCADE updates the child reference.
    • The exact MERGE source key move 2 -> 3, and sibling-source PICK KEYS(2), both return a foreign-key error and leave parent and child at 2.
    • Native ON UPDATE RESTRICT rejects atomically.
    • An independent source DELETE 2 plus INSERT 3 in one transaction also returns the FK error and preserves destination state. It must not be reclassified as an update.

    The production path makes a frontend-only correlation unsafe. multi_update.updateOneBatch writes an UPDATE as a delete followed by an insert. engine.ChangesHandle.Next exposes only independent data and tombstone batches, and databranchutils.BranchChangeHandle forwards that interface unchanged. findDeleteAndUpdateBat reconstructs the old LCA row from a tombstone, then probes replacement data by the deleted primary key. A key move has old key 2 and live key 3, so it has no association; an independent delete/insert has the same observable shape. Timestamp, transaction, row order, or values are not an operation identity and would spuriously invoke ON UPDATE actions. PICK additionally needs an explicit decision whether selecting old key 2 includes its replacement key 3.

    A correct solution therefore needs durable old-to-new update provenance with atomic publication through CN writes, TN/WAL, logtail, checkpoint/replay, CollectChanges, and every consumer. This is a persistent/wire/distributed-recovery protocol change, which triggers the repository design gate. Searches of docs/design, docs/rfcs, and related PRs found no approved versioned design for it; merged #27996 explicitly excludes primary-key moves.

    Blocking design decisions include identity encoding and retention/GC, update chains and key reuse, PICK old-key selection, compatibility and mixed-version behavior, checkpoint/restart/rollback, consumer semantics, and hot-path/resource bounds. Until an approved design resolves these, no safe implementation or executable fixed-success UT/BVT can be delivered. I am excluding this sole issue from PR delivery and replacing severity/s0 with deferred; no source change, commit, push, or Draft PR is appropriate.

  21. gouhongshen commented on Sep 9, 2026

    @gouhongshen
    ContributorAuthor

    Triage decision: defer.

    Revalidated the sole assigned member at HEAD = origin/main = 363f8c3fe63ab21f19d8e9ba854c24d2dcaadfc3; the final source diff is empty. I inspected CONTRIBUTING.md, the PR template, current MULTI_UPDATE producer, transaction/change-handle/replay contracts, Data Branch hashdiff/PICK consumers, and the existing stable-key FK BVTs. Merged #27996 explicitly excludes primary-key-changing updates.

    Fresh executable diagnostic: after building the required native artifacts with make cgo, .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=300s -run "^TestIssue28026Diagnostic$" ./pkg/tests/dml passed in 14.173s. The temporary probe was then removed. Its five assertions prove current behavior:

    • Native UPDATE parent SET id = 3 WHERE id = 2 with ON UPDATE CASCADE changes both parent and child.
    • The exact MERGE key move 2 -> 3 and sibling-branch PICK KEYS(2) both return an FK error and leave parent/child at 2.
    • Native ON UPDATE RESTRICT rejects atomically.
    • A source transaction containing independent DELETE 2 plus INSERT 3 also returns the FK error and leaves destination state unchanged.

    Root cause: an update writes separate delete and insert records. Transaction.WriteBatch carries individual operation entries; ChangesHandle.Next exports only a data batch and a tombstone batch. Replay emits data as rowid + values + commit timestamp and tombstones as rowid + primary key + timestamp. BranchChangeHandle forwards that interface, and findDeleteAndUpdateBat probes candidate replacements by the deleted primary key. The key move has deleted key 2 and live key 3, so it has no link; independent DELETE/INSERT has the same observable shape. Timestamp, transaction, order, or values are not an operation identity and would incorrectly turn real deletes into FK-cascading updates.

    A safe fix therefore requires durable old-to-new provenance with atomic publication through CN writes, storage/WAL, logtail/checkpoint replay, CollectChanges, and all consumers. This changes persistent and distributed-recovery contracts, triggering the design gate. Repository design/RFC searches and related-PR search found no approved versioned design. Blocking decisions include identity encoding and retention/GC, update chains/key reuse, PICK old-key selection, mixed-version and historical behavior, checkpoint/restart/rollback, consumer compatibility, and hot-path bounds.

    No heuristic workaround or failing-behavior regression was retained. To promote later: approve that design, then prove MERGE/PICK CASCADE success, native controls, RESTRICT failure atomicity, independent-operation non-conflation, key-selection boundaries, and checkpoint/restart persistence. This issue has no source change, commit, push, or PR.

  22. gouhongshen commented on Sep 9, 2026

    @gouhongshen
    ContributorAuthor

    Triage decision: defer.

    I revalidated the sole assigned issue at HEAD = origin/main = 363f8c3fe63a with a clean worktree. The latest current-head executable diagnostic is reusable: its exact storage/Data Branch source closure is unchanged, and its five public assertions establish that native UPDATE id=2 -> 3 with ON UPDATE CASCADE succeeds, while the exact Data Branch MERGE and sibling-branch PICK KEYS(2) both fail atomically with the parent and child retained at 2; native RESTRICT also rejects atomically; and an independent source DELETE 2 plus INSERT 3 in one transaction has the same failing Data Branch behavior. The temporary diagnostic was deliberately removed because it only asserts the unfixed behavior and cannot be a regression proof for a future fix.

    The root cause is unchanged. multi_update.updateOneBatch writes DELETE and INSERT separately. Insert writes allocate a new physical RowID. The transport converts writes only to insert/delete entries; partition-state replay supports insert/delete rather than a user-row update record; and ChangesHandle.Next exposes only data and tombstone batches. findDeleteAndUpdateBat reconstructs the LCA row from the tombstone and probes candidate replacement data by that deleted primary key. A key move has tombstone key 2 and data key 3, so it has no association. An independent DELETE/INSERT has the same observable shape.

    Correlating by timestamp, transaction, stream order, or value would therefore manufacture UPDATE semantics and could trigger an unintended ON UPDATE action. An in-memory marker would not survive logtail/checkpoint/replay. Searches of docs/design, docs/rfcs, and related Data Branch work found no approved durable update-provenance design.

    A safe implementation needs an approved persistent old-to-new provenance contract spanning CN writes, TN/WAL, logtail, checkpoint/replay, CollectChanges, and its consumers; it must also define retention/GC, update chains/key reuse, PICK old-key selection, mixed-version/history behavior, failure atomicity, and resource bounds.

    To promote later: approve that contract, then add fixed-success MERGE/PICK CASCADE BVTs plus RESTRICT atomicity, independent DELETE/INSERT non-conflation, selection-boundary, and restart/checkpoint coverage. No focused PR, commit, or source change is safe before that decision.

  23. gouhongshen commented on Sep 9, 2026

    @gouhongshen
    ContributorAuthor

    Triage decision: defer.

    I revalidated the sole assigned issue at HEAD = origin/main = cd04bb4. The worktree is source-clean. I read CONTRIBUTING.md, the PR template, the current MULTI_UPDATE producer, the persisted tombstone and replay/change-handle contracts, Data Branch hashdiff and PICK paths, and the nearby stable-key foreign-key BVTs. The merged #27996 scope explicitly excludes primary-key moves.

    Fresh executable evidence was obtained on this exact head with an isolated embedded single-CN/single-TN/single-Log instance built from this worktree. I ran a self-contained temporary BVT through mo-tester, inspected its generated result statement by statement, then ran the same case in normal comparison mode. The case proves all of the following current behaviors:

    • Native UPDATE parent id 2 to 4 with ON UPDATE CASCADE changes child.parent_id to 4.
    • The issue MERGE source move 2 to 3 reports INSERTED 1, DELETED 1, UPDATED 0, then fails with Cannot delete or update a parent row: a foreign key constraint fails. Parent and child remain at 2.
    • PICK from a source move 2 to 3 with KEYS(2) fails identically and leaves both destination rows unchanged.
    • An independent source DELETE 2 plus INSERT 3 in one transaction produces the same INSERTED 1, DELETED 1, UPDATED 0 summary and correctly fails rather than invoking ON UPDATE CASCADE. This is the non-conflation counterexample.

    Current source confirms why frontend-only repair is not sound. multi_update.updateOneBatch emits delete_table followed by insert_main_table. The tombstone contract persists only old RowID, old primary key, and commit metadata, while the replacement is an ordinary new data row. ChangesHandle and BranchChangeHandle expose independent data and tombstone batches. findDeleteAndUpdateBat and buildHashmapForTable correlate using the primary-key value; a tombstone at 2 cannot identify data at 3. The observed public diff is identical for the real UPDATE and the independent delete/insert counterexample. Timestamp, transaction membership, order, or values are not a durable operation identity and would manufacture UPDATE semantics, including unintended cascades.

    The narrowest correct change introduces durable old-to-new provenance and atomic publication across SQL/CN writes, storage/WAL, logtail, checkpoint/replay, CollectChanges, and its consumers. That changes persistent and cross-owner change-stream contracts, meeting the repository design-gate trigger. Searches of docs/design, docs/rfcs, and related PRs found no approved versioned provenance design. The required design decisions include identity representation and retention/GC, update chains and key reuse, PICK selection by old key, historical and mixed-version behavior, restart/checkpoint/rollback, consumer compatibility, and hot-path resource bounds.

    This missing approved protocol decision is the precise stopping reason. No heuristic or fabricated helper provenance was added, because it could not be a valid fixed-success regression. After design approval, executable acceptance must cover MERGE/PICK CASCADE success, native control, RESTRICT rejection and failure atomicity, independent-operation non-conflation, key-selection boundaries, and persistence/restart. This sole issue is excluded from PR delivery; no source change, commit, push, or Draft PR is appropriate.

  24. gouhongshen commented on Oct 28, 2026

    @gouhongshen
    ContributorAuthor

    PR #31629 is trying to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions