-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Temporarily disallow `SELECT FOR UPDATE` statements under all isolation levels that are not `SERIALIZABLE` (i.e. `SNAPSHOT` and `READ COMMITTED`). We will allow them again when the following issues are fixed: - cockroachdb#57031 - cockroachdb#75457 - cockroachdb#100193 - cockroachdb#100194 Fixes: cockroachdb#100144 Release note: None
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# LogicTest: !local-mixed-22.2-23.1 | ||
|
||
# SELECT FOR UPDATE is prohibited under weaker isolation levels until we improve | ||
# locking. See #57031, #75457, #100144. | ||
|
||
statement ok | ||
CREATE TABLE supermarket ( | ||
person STRING PRIMARY KEY, | ||
aisle INT NOT NULL, | ||
starts_with STRING GENERATED ALWAYS AS (left(person, 1)) STORED, | ||
ends_with STRING GENERATED ALWAYS AS (right(person, 3)) STORED, | ||
INDEX (starts_with), | ||
INDEX (ends_with) | ||
) | ||
|
||
statement ok | ||
INSERT INTO supermarket (person, aisle) | ||
VALUES ('abbie', 1), ('gideon', 2), ('matilda', 3), ('michael', 4) | ||
|
||
# SELECT FOR UPDATE should still work under serializable isolation. | ||
statement ok | ||
BEGIN | ||
|
||
query I | ||
SELECT aisle FROM supermarket WHERE person = 'gideon' FOR UPDATE | ||
---- | ||
2 | ||
|
||
statement ok | ||
UPDATE supermarket SET aisle = 2 WHERE person = 'abbie' | ||
|
||
statement ok | ||
COMMIT | ||
|
||
# It should fail under read committed isolation. | ||
statement ok | ||
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED | ||
|
||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation | ||
SELECT aisle FROM supermarket WHERE person = 'matilda' FOR UPDATE | ||
|
||
statement ok | ||
ROLLBACK | ||
|
||
# It should also fail under snapshot isolation. | ||
statement ok | ||
SET CLUSTER SETTING sql.txn.snapshot_isolation.enabled = true | ||
|
||
statement ok | ||
BEGIN TRANSACTION ISOLATION LEVEL SNAPSHOT | ||
|
||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under Snapshot isolation | ||
SELECT aisle FROM supermarket WHERE person = 'matilda' FOR UPDATE | ||
|
||
statement ok | ||
ROLLBACK | ||
|
||
statement ok | ||
RESET CLUSTER SETTING sql.txn.snapshot_isolation.enabled | ||
|
||
# SELECT FOR UPDATE in a subquery should also fail under read committed. | ||
statement ok | ||
BEGIN TRANSACTION | ||
|
||
statement ok | ||
SET TRANSACTION ISOLATION LEVEL READ COMMITTED; | ||
|
||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation | ||
UPDATE supermarket | ||
SET aisle = (SELECT aisle FROM supermarket WHERE person = 'matilda' FOR UPDATE) | ||
WHERE person = 'michael' | ||
|
||
statement ok | ||
ROLLBACK | ||
|
||
# It should also fail in a CTE. | ||
statement ok | ||
BEGIN TRANSACTION | ||
|
||
statement ok | ||
SET TRANSACTION ISOLATION LEVEL READ COMMITTED; | ||
|
||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation | ||
WITH s AS | ||
(SELECT aisle FROM supermarket WHERE person = 'matilda' FOR UPDATE) | ||
SELECT aisle + 1 FROM s | ||
|
||
statement ok | ||
ROLLBACK | ||
|
||
statement ok | ||
SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED | ||
|
||
# Creating a UDF using SELECT FOR UPDATE should succeed under read committed. | ||
statement ok | ||
CREATE FUNCTION wrangle (name STRING) RETURNS INT LANGUAGE SQL AS $$ | ||
SELECT aisle FROM supermarket WHERE person = name FOR UPDATE | ||
$$ | ||
|
||
# But calling that function should fail. | ||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation | ||
INSERT INTO supermarket (person, aisle) VALUES ('grandma', wrangle('matilda')) | ||
|
||
statement ok | ||
DROP FUNCTION wrangle | ||
|
||
# Preparing a SELECT FOR UPDATE should succeed under read committed. | ||
statement ok | ||
PREPARE psa AS SELECT aisle FROM supermarket WHERE person = $1::STRING FOR UPDATE | ||
|
||
# But execution should fail. | ||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation | ||
EXECUTE psa('matilda') | ||
|
||
statement ok | ||
DEALLOCATE psa | ||
|
||
# SELECT FOR UPDATE using a lookup join should also fail. | ||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation | ||
WITH names AS MATERIALIZED | ||
(SELECT 'matilda' AS person) | ||
SELECT aisle | ||
FROM names | ||
NATURAL INNER LOOKUP JOIN supermarket | ||
FOR UPDATE | ||
|
||
# SELECT FOR UPDATE using an index join should also fail. | ||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation | ||
SELECT aisle | ||
FROM supermarket@supermarket_starts_with_idx | ||
WHERE starts_with = 'm' | ||
FOR UPDATE | ||
|
||
# SELECT FOR UPDATE using a zigzag join should also fail. | ||
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation | ||
SELECT aisle | ||
FROM supermarket@{FORCE_ZIGZAG} | ||
WHERE starts_with = 'm' AND ends_with = 'lda' | ||
FOR UPDATE | ||
|
||
statement ok | ||
SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.