Skip to content

[4.2] fix(plan): lock base rows before irregular update fanout - #27222

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
LeftHandCold:backport/4.2-ivf-update-lock-order
Aug 17, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
LeftHandCold:backport/4.2-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 #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:

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:

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.

@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 17, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Aug 17, 2026
@XuPeng-SH
XuPeng-SH merged commit 7df8292 into matrixorigin:4.2-dev Aug 17, 2026
27 checks passed

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.

3 participants