Skip to content

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

Closed

Description

@LeftHandCold

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

6e282d2 (latest main used for code-path verification)

Other Environment Information

Actual Behavior

Concurrent updates of the same hot row on a table with a synchronously maintained IVF or full-text index can produce a real two-transaction deadlock. After #26925 removes uncertain cleanup-only locks from the wait-for graph, runtime logs still contain cycles between two different transactions, for example:

T1 <= T2 <= T1
T2 <= T1 <= T2

Both transactions update the same base-table primary key. Lock logs show waits on both the base table and the IVF entries hidden table. These are real lock edges, not the T <= T false self-cycle addressed by #26925.

The planner creates the inversion:

  1. bindUpdate builds the final row image in pkg/sql/plan/bind_update.go.
  2. For synchronous irregular indexes, appendOnDupIrregularMaintSource materializes that image into a SINK and records it as the source of the base-table and hidden-index maintenance plans.
  3. The base-table LOCK_OP is currently appended only after the returned SINK_SCAN, so it belongs only to the main MULTI_UPDATE consumer.
  4. IVF/full-text delete and insert maintenance are separate top-level steps consuming the same materialized source. They acquire locks on hidden tables independently of the main consumer.
  5. The top-level steps can execute concurrently. One transaction can therefore hold the base-row lock and wait for the hidden-table lock while another holds the hidden-table lock and waits for the same base row.

This ordering was introduced by #26518 (a2469ccbd4), which added modern UPDATE maintenance for synchronous irregular indexes but left the pre-existing base lock below the new fan-out boundary.

Expected Behavior

Every synchronous irregular-index maintenance branch must depend on acquisition of the base-table row lock. Concurrent transactions updating the same primary key should serialize at that base lock before any transaction can acquire a hidden-index lock.

The fix should move the existing lock before the shared row-image materialization only for UPDATEs that have synchronous irregular maintenance. It must not add a second lock or change the plan shape of ordinary UPDATEs.

Steps to Reproduce

CREATE TABLE test_vectors (
  id VARCHAR(64) PRIMARY KEY,
  embedding VECF32(128),
  content TEXT
);
CREATE INDEX idx_vec USING ivfflat ON test_vectors(embedding)
  lists=10 op_type 'vector_l2_ops';
INSERT INTO test_vectors VALUES ('hot-id', '[...]', 'initial');

Run several concurrent sessions that repeatedly execute the following statement against hot-id with different vector/content values:

UPDATE test_vectors
SET embedding = '[...]', content = 'updated'
WHERE id = 'hot-id';

The existing ivf_dml_scenarios.py update_embedding workload in #27124 is a production-reachable witness: all updater workers select LIMIT 1 from the same predicate before UPDATE and converge on the same hot primary key. Before the planner fix, the workload reports 20701 deadlock detected and the server records real two-transaction cycles.

Additional information

A deterministic planner regression can prove the violated invariant without timing: inspect the shared irregular-maintenance SINK and assert that its source subtree contains the base-table LOCK_OP. The assertion fails on current main because the lock is downstream in only the main DML consumer.

The proposed topology is:

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

This preserves the existing lock set and transaction semantics while establishing one lock order for every consumer.

Activity

  1. LeftHandCold commented on Aug 14, 2026

    @LeftHandCold
    CollaboratorAuthor

    Fix proposed in #27144.

    Post-rebase verification was repeated on main de40fe49fd with PR commit a3a8af935a:

    • the planner invariant test fails on the unfixed code because the shared irregular-maintenance SINK has no base-table lock in its source subtree;
    • the same test passes after moving the existing lock before the fan-out, for both IVF and full-text;
    • ordinary UPDATE retains MULTI_UPDATE -> LOCK_OP without a new materialization step;
    • pkg/sql/plan passes in normal and race modes;
    • the embedded full-text blocking/cancel/rollback/retry/index-consistency regression passes.

    No lockservice, RPC, wire-format, or release-branch changes are included.

  2. self-assigned this
    on Aug 14, 2026
  3. added
    severity/s0
    and removed on Aug 14, 2026
  4. added 2 commits that reference this issue on Aug 14, 2026
    64561b2
    7df8292
  5. added 3 commits that reference this issue on Sep 17, 2026
    adb43eb
    e122a9a
    0d9ba86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions