Skip to content

fix(plan): lock base rows before irregular update fanout - #27144

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/ivf-update-lock-order
Aug 14, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/ivf-update-lock-order

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

Fixes #27142

Related to #27124, #26925, and #26518.

What this PR does / why we need it:

Root cause

#26518 moved synchronous IVF/full-text UPDATE maintenance to separate top-level steps that consume a shared materialized final-row image. The pre-existing base-table LOCK_OP remained downstream of that materialization in only the main MULTI_UPDATE consumer.

The main consumer and hidden-index consumers could therefore acquire locks independently:

T1: base row -> waits for IVF entries row
T2: IVF entries row -> waits for base row

Production logs after the false self-cycle fix in #26925 contain real cycles between two different transactions updating the same primary key. These are genuine wait edges, so changing deadlock detection would hide the symptom rather than repair the lock order.

Fix

For UPDATEs with synchronous irregular-index maintenance, move the existing base/regular-index LOCK_OP before the shared row-image SINK:

final row image
  -> existing LOCK_OP
  -> shared SINK
     -> base MULTI_UPDATE
     -> irregular delete maintenance
     -> irregular insert maintenance

Every downstream consumer now receives a row only after its base lock has been acquired. A second transaction updating the same primary key waits at that gate before it can acquire a hidden-table lock.

This PR does not add locks or change lock modes, commit-time release, RPC formats, or lockservice behavior. UPDATEs without synchronous irregular maintenance keep their existing plan shape. Async indexes remain CDC-only.

Risk assessment

  • Normal UPDATEs do not enter the changed branch.
  • Synchronous IVF/full-text UPDATEs execute the same lock operation earlier in the same transaction; uncontended lock work and lock cardinality are unchanged.
  • Lock failure/cancellation now happens before hidden-table maintenance starts, reducing partial-work exposure.
  • Existing embedded full-text coverage verifies blocking, cancellation, rollback, retry, and hidden-index consistency.

Tests

  • Added a deterministic planner regression for both IVF and full-text asserting that the shared maintenance sink depends on the base-table lock.
  • Added a control asserting ordinary UPDATE keeps LOCK_OP directly at the DML input.
  • Verified the new invariant fails on unfixed main and passes with this PR.
  • go build -mod=readonly ./pkg/sql/plan
  • go vet -mod=readonly ./pkg/sql/plan
  • go test -count=1 ./pkg/sql/plan
  • go test -race -count=1 ./pkg/sql/plan
  • Focused planner regressions with -race -count=100
  • TestIssue26341CancelAndRetryFulltextUpdate embedded-cluster regression

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Aug 14, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Aug 14, 2026
@LeftHandCold
LeftHandCold force-pushed the fix/ivf-update-lock-order branch from a3a8af9 to 49a1f7a Compare August 14, 2026 14:03

@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 review completed at e9ea9b5. No blocking findings.

Verified the invariant end to end: for synchronous IVF/fulltext/master UPDATE maintenance, the shared row-image SINK is now downstream of the existing LOCK_OP, and the runtime lock operator acquires all base/regular-index targets for each batch before that batch can fan out to hidden-table delete/insert consumers. Ordinary and async-index UPDATE routes keep their prior topology.

Also checked projection/remapping closure (including multi-target selector columns and existing preserved-lock users), lock-table/no-row handling, hidden-table key conflicts, and cancel/retry behavior. Local validation passed: full ./pkg/sql/plan tests and the three new focused tests under -race.

@mergify mergify Bot added the queued label Aug 14, 2026
@mergify

mergify Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

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

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

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

Reason

Pull request #27144 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, 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.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 64561b2 into matrixorigin:main Aug 14, 2026
22 of 24 checks passed
@mergify mergify Bot added dequeued and removed queued labels Aug 14, 2026
XuPeng-SH pushed a commit that referenced this pull request Aug 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes #27124

Backport of #27144. Related to #27142, #26925, and #26518.

## What this PR does / why we need it:

### Root cause

#26518 moved synchronous IVF/full-text UPDATE maintenance to separate
top-level steps that consume a shared materialized final-row image. The
existing base/regular-index `LOCK_OP` remained downstream of that
materialization in only the main `MULTI_UPDATE` consumer.

The base consumer and hidden-index consumers could therefore acquire
locks in opposite order:

```text
T1: base row -> waits for IVF/full-text hidden row
T2: IVF/full-text hidden row -> waits for base row
```

#26925 removes false self-cycles from deadlock detection, but it cannot
remove these real two-transaction cycles.

### Fix

For UPDATEs with synchronous irregular-index maintenance, move the
existing base/regular-index `LOCK_OP` before the shared row-image
`SINK`:

```text
final row image
  -> existing LOCK_OP
  -> shared SINK
     -> base MULTI_UPDATE
     -> irregular delete maintenance
     -> irregular insert maintenance
```

Preserve the complete positional row image through the moved lock gate
so all sink consumers continue to resolve the same columns.

This is a semantic backport because the original main commit conflicts
with the current 4.2 planner implementation. It retains #27144's
lock-order invariant while adapting to the 4.2 UPDATE fanout helper. 4.2
does not support master-index UPDATE, so the regression covers its
reachable IVF and full-text paths.

### Risk assessment

- No new lock, lock mode, release rule, RPC, or lockservice behavior is
introduced.
- Normal UPDATEs keep `MULTI_UPDATE -> LOCK_OP`.
- Synchronous IVF/full-text UPDATEs execute the same lock operation
once, earlier in the same transaction.
- Async indexes remain CDC-only.

### Tests

- Verified the new planner regression fails on clean 4.2-dev
`aaac5956fd` for both IVF and full-text because the maintenance fanout
has no upstream base lock.
- `pkg/sql/plan` full package test.
- Focused planner regressions with `-count=10`.
- `go vet ./pkg/sql/plan`.
- `TestIssue26341CancelAndRetryFulltextUpdate` embedded three-CN
regression, covering lock blocking, cancellation, rollback, retry, and
hidden-index consistency.
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#27144)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27142

Related to matrixorigin#27124, matrixorigin#26925, and matrixorigin#26518.

## What this PR does / why we need it:

### Root cause

matrixorigin#26518 moved synchronous IVF/full-text UPDATE maintenance to separate
top-level steps that consume a shared materialized final-row image. The
pre-existing base-table `LOCK_OP` remained downstream of that
materialization in only the main `MULTI_UPDATE` consumer.

The main consumer and hidden-index consumers could therefore acquire
locks independently:

```text
T1: base row -> waits for IVF entries row
T2: IVF entries row -> waits for base row
```

Production logs after the false self-cycle fix in matrixorigin#26925 contain real
cycles between two different transactions updating the same primary key.
These are genuine wait edges, so changing deadlock detection would hide
the symptom rather than repair the lock order.

### Fix

For UPDATEs with synchronous irregular-index maintenance, move the
existing base/regular-index `LOCK_OP` before the shared row-image
`SINK`:

```text
final row image
  -> existing LOCK_OP
  -> shared SINK
     -> base MULTI_UPDATE
     -> irregular delete maintenance
     -> irregular insert maintenance
```

Every downstream consumer now receives a row only after its base lock
has been acquired. A second transaction updating the same primary key
waits at that gate before it can acquire a hidden-table lock.

This PR does not add locks or change lock modes, commit-time release,
RPC formats, or lockservice behavior. UPDATEs without synchronous
irregular maintenance keep their existing plan shape. Async indexes
remain CDC-only.

### Risk assessment

- Normal UPDATEs do not enter the changed branch.
- Synchronous IVF/full-text UPDATEs execute the same lock operation
earlier in the same transaction; uncontended lock work and lock
cardinality are unchanged.
- Lock failure/cancellation now happens before hidden-table maintenance
starts, reducing partial-work exposure.
- Existing embedded full-text coverage verifies blocking, cancellation,
rollback, retry, and hidden-index consistency.

### Tests

- Added a deterministic planner regression for both IVF and full-text
asserting that the shared maintenance sink depends on the base-table
lock.
- Added a control asserting ordinary UPDATE keeps `LOCK_OP` directly at
the DML input.
- Verified the new invariant fails on unfixed main and passes with this
PR.
- `go build -mod=readonly ./pkg/sql/plan`
- `go vet -mod=readonly ./pkg/sql/plan`
- `go test -count=1 ./pkg/sql/plan`
- `go test -race -count=1 ./pkg/sql/plan`
- Focused planner regressions with `-race -count=100`
- `TestIssue26341CancelAndRetryFulltextUpdate` embedded-cluster
regression

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#27144)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27142

Related to matrixorigin#27124, matrixorigin#26925, and matrixorigin#26518.

## What this PR does / why we need it:

### Root cause

matrixorigin#26518 moved synchronous IVF/full-text UPDATE maintenance to separate
top-level steps that consume a shared materialized final-row image. The
pre-existing base-table `LOCK_OP` remained downstream of that
materialization in only the main `MULTI_UPDATE` consumer.

The main consumer and hidden-index consumers could therefore acquire
locks independently:

```text
T1: base row -> waits for IVF entries row
T2: IVF entries row -> waits for base row
```

Production logs after the false self-cycle fix in matrixorigin#26925 contain real
cycles between two different transactions updating the same primary key.
These are genuine wait edges, so changing deadlock detection would hide
the symptom rather than repair the lock order.

### Fix

For UPDATEs with synchronous irregular-index maintenance, move the
existing base/regular-index `LOCK_OP` before the shared row-image
`SINK`:

```text
final row image
  -> existing LOCK_OP
  -> shared SINK
     -> base MULTI_UPDATE
     -> irregular delete maintenance
     -> irregular insert maintenance
```

Every downstream consumer now receives a row only after its base lock
has been acquired. A second transaction updating the same primary key
waits at that gate before it can acquire a hidden-table lock.

This PR does not add locks or change lock modes, commit-time release,
RPC formats, or lockservice behavior. UPDATEs without synchronous
irregular maintenance keep their existing plan shape. Async indexes
remain CDC-only.

### Risk assessment

- Normal UPDATEs do not enter the changed branch.
- Synchronous IVF/full-text UPDATEs execute the same lock operation
earlier in the same transaction; uncontended lock work and lock
cardinality are unchanged.
- Lock failure/cancellation now happens before hidden-table maintenance
starts, reducing partial-work exposure.
- Existing embedded full-text coverage verifies blocking, cancellation,
rollback, retry, and hidden-index consistency.

### Tests

- Added a deterministic planner regression for both IVF and full-text
asserting that the shared maintenance sink depends on the base-table
lock.
- Added a control asserting ordinary UPDATE keeps `LOCK_OP` directly at
the DML input.
- Verified the new invariant fails on unfixed main and passes with this
PR.
- `go build -mod=readonly ./pkg/sql/plan`
- `go vet -mod=readonly ./pkg/sql/plan`
- `go test -count=1 ./pkg/sql/plan`
- `go test -race -count=1 ./pkg/sql/plan`
- Focused planner regressions with `-race -count=100`
- `TestIssue26341CancelAndRetryFulltextUpdate` embedded-cluster
regression

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…n#27144)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Fixes matrixorigin#27142

Related to matrixorigin#27124, matrixorigin#26925, and matrixorigin#26518.

## What this PR does / why we need it:

### Root cause

matrixorigin#26518 moved synchronous IVF/full-text UPDATE maintenance to separate
top-level steps that consume a shared materialized final-row image. The
pre-existing base-table `LOCK_OP` remained downstream of that
materialization in only the main `MULTI_UPDATE` consumer.

The main consumer and hidden-index consumers could therefore acquire
locks independently:

```text
T1: base row -> waits for IVF entries row
T2: IVF entries row -> waits for base row
```

Production logs after the false self-cycle fix in matrixorigin#26925 contain real
cycles between two different transactions updating the same primary key.
These are genuine wait edges, so changing deadlock detection would hide
the symptom rather than repair the lock order.

### Fix

For UPDATEs with synchronous irregular-index maintenance, move the
existing base/regular-index `LOCK_OP` before the shared row-image
`SINK`:

```text
final row image
  -> existing LOCK_OP
  -> shared SINK
     -> base MULTI_UPDATE
     -> irregular delete maintenance
     -> irregular insert maintenance
```

Every downstream consumer now receives a row only after its base lock
has been acquired. A second transaction updating the same primary key
waits at that gate before it can acquire a hidden-table lock.

This PR does not add locks or change lock modes, commit-time release,
RPC formats, or lockservice behavior. UPDATEs without synchronous
irregular maintenance keep their existing plan shape. Async indexes
remain CDC-only.

### Risk assessment

- Normal UPDATEs do not enter the changed branch.
- Synchronous IVF/full-text UPDATEs execute the same lock operation
earlier in the same transaction; uncontended lock work and lock
cardinality are unchanged.
- Lock failure/cancellation now happens before hidden-table maintenance
starts, reducing partial-work exposure.
- Existing embedded full-text coverage verifies blocking, cancellation,
rollback, retry, and hidden-index consistency.

### Tests

- Added a deterministic planner regression for both IVF and full-text
asserting that the shared maintenance sink depends on the base-table
lock.
- Added a control asserting ordinary UPDATE keeps `LOCK_OP` directly at
the DML input.
- Verified the new invariant fails on unfixed main and passes with this
PR.
- `go build -mod=readonly ./pkg/sql/plan`
- `go vet -mod=readonly ./pkg/sql/plan`
- `go test -count=1 ./pkg/sql/plan`
- `go test -race -count=1 ./pkg/sql/plan`
- Focused planner regressions with `-race -count=100`
- `TestIssue26341CancelAndRetryFulltextUpdate` embedded-cluster
regression

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: irregular-index UPDATE can invert base and hidden-table lock order

3 participants