sql: SELECT FOR UPDATE does not prevent insertion of new rows (phantoms) #120673
Labels
A-read-committed
Related to the introduction of Read Committed
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
docs-done
docs-known-limitation
T-kv
KV Team
Projects
Regardless of isolation level,
SELECT FOR UPDATE
andSELECT FOR SHARE
statements in CockroachDB do not prevent insertion of new rows matching the search condition (a.k.a. phantoms). This is the same as PostgreSQL behavior at all isolation levels, but can be a little surprising.Here's a demonstration:
Other databases have different behavior. E.g. in MySQL using InnoDB, under
REPEATABLE READ
isolation and higher, the final insert and update will block thanks to InnoDB's next-key locks (a.k.a. gap locks or predicate locks).As mentioned here, we're planning to add support for single-key predicate locking (i.e. on
Get
) in order to allow uniqueness checks on regional by row tables under read committed isolation. That won't be sufficient to change this behavior of SELECT FOR UPDATE, however. To make SELECT FOR UPDATE prevent phantoms in all cases, we would need multi-key predicate locking (i.e. predicate locking onScan
).Jira issue: CRDB-36814
The text was updated successfully, but these errors were encountered: