-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[YSQL] #1199: Enable FOR SHARE and FOR KEY SHARE row locking in YSQL …
…SELECT statements Summary: Support row-level explicit locking in `SELECT` statements for YSQL tables. The new supported cases are: - `SELECT .. FOR SHARE` - `SELECT .. FOR KEY SHARE` Additionally, since the `FOR KEY SHARE` case is also used internally for referential integrity checking (i.e. foreign keys), this diff also enables DMLs on tables with foreign key references regardless of isolation level (previously only worked in `SERIALIZABLE` isolation). Implementation is done by passing the row mark as flag in the DocDB read request and taking appropriate lock for those requests that have that corresponding row mark. Limitations (that will be addressed in follow-up commits): - The `FOR UPDATE` and `FOR NO KEY UPDATE` are not yet supported - The locking for `FOR KEY SHARE` is stronger than strictly required (strong read lock instead of weak read lock). This is still correct but less efficient (will conflict more often than required). - We don't support having different row mark settings within one DocDB (read) batch. This is fine for now because we do not batch such requests together, but later we might. The current implementation makes data visible between two transactions when it shouldn't. This is because we are currently not detecting read conflicts. #2523 tracks this issue. Test Plan: Java test testForeignKeyConflicts has been converted to two tests: testForeignKeyConflictsWithSerializableIsolation and testForeignKeyConflictsWithSnapshotIsolation/ ```postgres=# create table t(k int primary key, s text); CREATE TABLE postgres=# select * from t where k = 1 for key share; k | s ---+--- (0 rows) postgres=# insert into t(k, s) values (1, 'a'); INSERT 0 1 postgres=# select * from t where k = 1 for key share; k | s ---+--- 1 | a (1 row) postgres=# select * from t for key share; k | s ---+--- 1 | a (1 row) ``` ```postgres=# create table t(k int primary key, s text); CREATE TABLE postgres=# insert into t(k, s) values (1, 'a'); INSERT 0 1 postgres=# begin; BEGIN postgres=# insert into t(k,s) values (2, 'b'); INSERT 0 1 postgres=# select * from t for key share; k | s ---+--- 1 | a 2 | b (2 rows) postgres=# select * from t where k = 1 for key share; k | s ---+--- 1 | a (1 row) postgres=# abort; ROLLBACK postgres=# select * from t where k = 1 for key share; k | s ---+--- 1 | a (1 row) postgres=# select * from t for key share; k | s ---+--- 1 | a (1 row) ``` ``` postgres=# create table t(id int primary key, s text); CREATE TABLE postgres=# create table s(id int primary key , t_id int references t(id)); CREATE TABLE postgres=# insert into t(id, s) values (1, 'a'); INSERT 0 1 postgres=# insert into t(id, s) values (2, 'b'); INSERT 0 1 postgres=# insert into s(id, t_id) values (100, 1); INSERT 0 1 postgres=# select s.id, t.s from s, t where s.t_id = t.id; id | s -----+--- 100 | a (1 row) postgres=# begin; BEGIN postgres=# delete from t where id = 2; DELETE 1 postgres=# select * from t; id | s ----+--- 1 | a (1 row) postgres=# commit; COMMIT postgres=# select * from t; id | s ----+--- 1 | a (1 row) ``` Reviewers: mihnea, mikhail Reviewed By: mikhail Subscribers: bogdan, yql Differential Revision: https://phabricator.dev.yugabyte.com/D7007
- Loading branch information
Showing
26 changed files
with
241 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.