Skip to content

fix(plan): maintain irregular indexes in modern update - #26518

Merged
mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-26341-main
Jul 31, 2026
Merged

mergify[bot] merged 5 commits into
matrixorigin:mainfrom
ck89119:issue-26341-main

Conversation

@ck89119

@ck89119 ck89119 commented Jul 31, 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 #26341

What this PR does / why we need it:

The modern UPDATE planner previously routed affected FULLTEXT and vector indexes back to the legacy planner because it could not maintain their hidden tables. This prevented the UPDATE planner migration from completing and made index behavior depend on planner fallback.

This change keeps plugin-supported irregular indexes on the modern planner path:

  • classifies synchronous and asynchronous indexes through plugin metadata and update-column hooks;
  • materializes the final UPDATE row image once and shares it with the base-table mutation and synchronous hidden-index delete/insert plans;
  • keeps asynchronous indexes CDC-only;
  • rejects primary-key updates when a synchronous irregular index would otherwise retain hidden rows keyed by the old primary key;
  • covers indexed columns, included columns, implicit ON UPDATE columns, route selection, and legacy handling for algorithms not yet migrated to the plugin contract.

Validation:

  • make -j8
  • make static-check
  • .agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/sql/plan
  • .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 ./pkg/sql/plan
  • focused planner tests with -race -count=100
  • vector_ivfflat_include_dml_sync.sql (25/25)
  • fulltext_update_pk.sql (21/21)
  • fulltext.sql (255/255)
  • manual transaction commit/rollback checks for synchronous FULLTEXT maintenance

@mergify

mergify Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-31 15:41 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-07-31 16:18 UTC · at 7cde37cf0e044801050803893f070ec9eabf5c94 · squash

This pull request spent 36 minutes 38 seconds in the queue, including 36 minutes 15 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 Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • 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)
  • 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

@mergify
mergify Bot merged commit a2469cc into matrixorigin:main Jul 31, 2026
26 of 27 checks passed
@mergify mergify Bot removed the queued label Jul 31, 2026
@ck89119
ck89119 deleted the issue-26341-main branch August 1, 2026 05:29
XuPeng-SH pushed a commit that referenced this pull request Aug 14, 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 #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:

```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 #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>
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
…26518)

The modern UPDATE planner previously routed affected FULLTEXT and vector indexes back to the legacy planner because it could not maintain their hidden tables. This prevented the UPDATE planner migration from completing and made index behavior depend on planner fallback.

This change keeps plugin-supported irregular indexes on the modern planner path:

- classifies synchronous and asynchronous indexes through plugin metadata and update-column hooks;
- materializes the final UPDATE row image once and shares it with the base-table mutation and synchronous hidden-index delete/insert plans;
- keeps asynchronous indexes CDC-only;
- rejects primary-key updates when a synchronous irregular index would otherwise retain hidden rows keyed by the old primary key;
- covers indexed columns, included columns, implicit `ON UPDATE` columns, route selection, and legacy handling for algorithms not yet migrated to the plugin contract.

Validation:

- `make -j8`
- `make static-check`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/sql/plan`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 ./pkg/sql/plan`
- focused planner tests with `-race -count=100`
- `vector_ivfflat_include_dml_sync.sql` (25/25)
- `fulltext_update_pk.sql` (21/21)
- `fulltext.sql` (255/255)
- manual transaction commit/rollback checks for synchronous FULLTEXT maintenance

Approved by: @heni02, @XuPeng-SH
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
…26518)

The modern UPDATE planner previously routed affected FULLTEXT and vector indexes back to the legacy planner because it could not maintain their hidden tables. This prevented the UPDATE planner migration from completing and made index behavior depend on planner fallback.

This change keeps plugin-supported irregular indexes on the modern planner path:

- classifies synchronous and asynchronous indexes through plugin metadata and update-column hooks;
- materializes the final UPDATE row image once and shares it with the base-table mutation and synchronous hidden-index delete/insert plans;
- keeps asynchronous indexes CDC-only;
- rejects primary-key updates when a synchronous irregular index would otherwise retain hidden rows keyed by the old primary key;
- covers indexed columns, included columns, implicit `ON UPDATE` columns, route selection, and legacy handling for algorithms not yet migrated to the plugin contract.

Validation:

- `make -j8`
- `make static-check`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 ./pkg/sql/plan`
- `.agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 ./pkg/sql/plan`
- focused planner tests with `-race -count=100`
- `vector_ivfflat_include_dml_sync.sql` (25/25)
- `fulltext_update_pk.sql` (21/21)
- `fulltext.sql` (255/255)
- manual transaction commit/rollback checks for synchronous FULLTEXT maintenance

Approved by: @heni02, @XuPeng-SH
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/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Subtask]: Move synchronous irregular-index UPDATE maintenance to the modern planner

3 participants