Skip to content

fix(sql): support distinct-table multi-target updates - #26923

Merged
mergify[bot] merged 41 commits into
matrixorigin:mainfrom
ck89119:issue-26340-core-main
Aug 14, 2026
Merged

mergify[bot] merged 41 commits into
matrixorigin:mainfrom
ck89119:issue-26340-core-main

Conversation

@ck89119

@ck89119 ck89119 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

fixes #26340

What this PR does / why we need it:

This is stage 1 of the multi-target UPDATE work. It establishes the execution and protocol foundation for statements that update distinct physical tables, while explicitly rejecting multiple writable aliases of the same physical table until stage 2 implements their alias-level semantics.

This change:

  • routes distinct-table multi-target UPDATE statements through the modern MULTI_UPDATE path;
  • gives every physical target an independent active/row-number selector so UPDATE IGNORE and outer joins do not discard rows belonging to another target;
  • propagates PRE_INSERT target selectors through plan/pipeline protobufs, deep copy, operator duplication, and remote execution;
  • supports multiple AUTO_INCREMENT targets without consuming sequence values for inactive or duplicate source rows;
  • uses database/object identity for runtime update contexts, allowing same-named targets from different databases;
  • keeps base/index contexts on one filtered target batch for table, S3, and partition writers;
  • closes partition writer Reset/Free lifecycle ownership; and
  • adds planner, executor, serialization, partition, AUTO_INCREMENT, cross-database, and distributed regression coverage.

Repeated writable aliases of one physical table return a deterministic not-supported error in this stage. A follow-up PR based on this branch will implement alias-level merge, constraint, generated-column, IGNORE, and affected-row semantics.

Validation:

  • full tests: pkg/common/moerr, pkg/pb/plan, pkg/pb/pipeline, pkg/sql/colexec/preinsert, pkg/sql/colexec/multi_update, pkg/sql/compile, pkg/sql/plan
  • build and vet for all packages above
  • TestPartitionMultiUpdateResetReleasesWriters with -race -count=100
  • full pkg/sql/colexec/multi_update with -race
  • isolated update_multi_target_modern BVT: 163/163 statements passed
  • make build
  • make generate-pb with stable generated-file hashes
  • git diff --check

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head 592ab075294bf65e1f041e40c1e82318a22938c2 after my previous CHANGES_REQUESTED.

The prior partitioned outer-join blocker is closed at the correct ownership boundary: target activation/row-number selection now happens before partition pruning, and both ordinary partition routing and the old/new partition-key phases consume the same already-filtered batch. The cloned physical contexts disable a second selection/accounting pass. I also checked Reset/Prepare reuse: the retained S3 delegate refreshes its seen-row map, admission callback, and affected-row callback after the old selector state is freed.

The updated multi_update, preinsert, protobuf, compile, and planner suites pass; the new selector/reuse tests pass under race; build and vet pass. Current CI is green.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction after completing the current-head resource-ownership audit: one P1 blocker remains in the partitioned S3 path.

PartitionMultiUpdate.selectPartitionTargetRows grows op.raw.ctr.seenTargetRows before partition routing, but it never measures that growth or calls op.raw.admitSeenTargetRowsGrowth. The downstream physical/phase contexts intentionally set DedupByTargetRowID=false, so s3WriterDelegate.append snapshots the map only after the growth and observes a zero delta. The hashmap therefore bypasses CNMemoryThrottler while remaining retained until Reset/Free.

I independently reproduced this at exact head 592ab075294bf65e1f041e40c1e82318a22938c2: selecting one new Rowid grew the map from 0 to 32,856 bytes, while the test throttler acquired 0 bytes.

Please measure/admit the pre-prune selector growth on UpdateWriteS3 (preserving Reset/Free release and error cleanup), or remove this dormant cross-alias state from stage 1. Add a regression that executes the selector-to-admission boundary; varying only Action in the existing selection test does not traverse S3 admission.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Account the pre-prune Rowid selector growth on the partitioned S3 path.

writeTarget now calls selectPartitionTargetRows before routing, and that call inserts into op.raw.ctr.seenTargetRows. For UpdateWriteS3, the later physical contexts deliberately set DedupByTargetRowID=false, so s3WriterDelegate.append takes its seenSizeBefore snapshot after this growth and observes a zero increment. No call to op.raw.admitSeenTargetRowsGrowth exists around the selector, so the retained map can grow without acquiring from CNMemoryThrottler until Reset/Free.

Please measure and admit the selector growth before partition routing (while preserving the existing release path), and add a regression that actually exercises the selector-to-S3-admission boundary; varying the action while calling the selector alone cannot validate that contract.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed exact head 9461356, including the complete prior review history. All previous blockers are closed: same-chunk RowID duplicates are filtered correctly; target selection happens before partition pruning without a second dedup pass; retained S3 selector state is refreshed across Reset/Prepare; selector hashmap growth is admitted through CNMemoryThrottler and released on lifecycle cleanup, with both grant and rejection covered; the temporary scratch files are gone; and the post-merge protobuf output retains both the target-selector fields and upstream fields. Verification passed: affected package tests across moerr, plan/pipeline protobufs, preinsert, multi_update, compile, and planner; plus focused -race tests for selector admission, rejection/release, reset/reuse, partition routing, and within-/cross-batch dedup.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep-reviewed exact head 9461356, including the complete prior review history and latest selector-admission fixes. No blocking issue found. The previous partition-pruning, same-chunk/cross-batch RowID dedup, Reset/Prepare selector reuse, and partitioned-S3 memory-admission blockers are closed at their ownership boundaries. I also rechecked distinct-target planner isolation, UPDATE IGNORE branches, auto-increment selectors, partition/index and FK/irregular-index routing, remote protocol gating, and Reset/Free cleanup. Full affected-package tests, focused race tests, go vet, protobuf tests, and diff checks pass locally. GitHub has no failed checks; Ubuntu UT and pessimistic standalone BVT are still running under branch protection.

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 9461356, including the previously reported partition-pruning, cross-batch deduplication, S3 reset/reuse, scratch-artifact, and retained-memory concerns. Those paths are closed in this revision.

I traced the stage-1 contract through independent per-target selectors, target-local lazy evaluation, outer-join NULL filtering, UPDATE IGNORE branch splitting, generated/on-update/check/FK/index handling, deterministic locks, partition delete/insert routing, remote protocol v18, S3 memory admission, and Reset/Prepare/Free ownership. Repeated writable aliases are explicitly rejected as documented for stage 2. I found no remaining production-reachable correctness, performance, or lifecycle blocker. Current CI is green; I deliberately did not rerun heavy local UT/BVT.

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 9461356. The partitioned S3 path now measures the shared Rowid selector map before target selection, admits only the new S3-retained growth, and releases the grant during cleanup. The added regression covers grant, rejection, and release; no additional blocker found.

@mergify

mergify Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-12 16:52 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-08-12 20:43 UTC · at 216aee643d5afdc041fdcf70513f3d6bb7081c55

This pull request spent 3 hours 50 minutes 27 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86

Reason

The merge conditions cannot be satisfied due to failing checks

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-13 13:01 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-08-13 13:02 UTC · at 83c0473683b795f4dfc33bbe1719943dd11eb2fa

This pull request spent 42 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/iceberg-connector.yml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-13 14:58 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-08-13 15:09 UTC · at e414028f09ab136907b1d39d23bda15f03796d17

This pull request spent 11 minutes 24 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/sca-go-module-cache.yaml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-13 17:28 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-08-13 17:28 UTC · at 50403eb51abf5a411755893fde60d2228443fc59

This pull request spent 22 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

For security reasons, Mergify can't update this pull request. Try updating locally.
GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/sca-go-module-cache.yaml without workflows permission

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

# Conflicts:
#	pkg/defines/const.go
#	pkg/pb/pipeline/pipeline.pb.go
#	pkg/pb/plan/plan.pb.go
@mergify

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-14 04:06 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-14 06:44 UTC · at aacea4b5a3e757e8fd2d0f27380f5c98b871e756 · squash

This pull request spent 2 hours 37 minutes 35 seconds in the queue, including 48 minutes 6 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

This branch was previously deployed

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

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subtask]: Move multi-target UPDATE semantics to MULTI_UPDATE

6 participants