Repository navigation
Description
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
- Distributed deployment with multiple CNs
- Reproduced by the IVF
update_embeddingstability workload tracked in IVF vector UPDATE deadlock: 39% failure rate on concurrent update_embedding scenario (4.2-dev regression) #27124 - Related but distinct from the false self-cycle fixed by fix(lockservice): exclude uncertain locks from deadlock graph #26925
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:
bindUpdatebuilds the final row image inpkg/sql/plan/bind_update.go.- For synchronous irregular indexes,
appendOnDupIrregularMaintSourcematerializes that image into aSINKand records it as the source of the base-table and hidden-index maintenance plans. - The base-table
LOCK_OPis currently appended only after the returnedSINK_SCAN, so it belongs only to the mainMULTI_UPDATEconsumer. - 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.
- 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
LeftHandCold commentedon Aug 14, 2026
Fix proposed in #27144.
Post-rebase verification was repeated on main
de40fe49fdwith PR commita3a8af935a:SINKhas no base-table lock in its source subtree;MULTI_UPDATE -> LOCK_OPwithout a new materialization step;pkg/sql/planpasses in normal and race modes;No lockservice, RPC, wire-format, or release-branch changes are included.
fix(plan): lock base rows before irregular update fanout (#27144)
[4.2] fix(plan): lock base rows before irregular update fanout (#27222)
fix(plan): lock base rows before irregular update fanout (matrixorigi…
fix(plan): lock base rows before irregular update fanout (matrixorigi…
fix(plan): lock base rows before irregular update fanout (matrixorigi…