Skip to content

Commit 6a3e43d

Browse files
committed
opt: do not use LockDurabilityGuaranteed under serializable isolation
This is a follow-up from cockroachdb#103734. We do not want to use guaranteed-durable (a.k.a. replicated) locking under serializable isolation, because it prevents pipelining and other optimizations, and is unnecessary for correctness. This commit ammends 8cbc6d1 to only set durability for `SELECT FOR UPDATE` locking under weaker isolation levels. This means that query plans will be slightly different under different isolation levels, and so we must add isolation level to the optimizer memo staleness calculation. Furthermore, this commit changes the error message added by e633d5e to be about guaranteed-durable locking rather than `SELECT FOR UPDATE`, because in a later commit this specific error will also be triggered by foreign key checks under weaker isolation levels. Informs: cockroachdb#100144, cockroachdb#100156, cockroachdb#100193, cockroachdb#100194 Release note: None
1 parent 30e194f commit 6a3e43d

File tree

12 files changed

+46
-172
lines changed

12 files changed

+46
-172
lines changed

pkg/sql/logictest/testdata/logic_test/read_committed

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ COMMIT
3838
statement ok
3939
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED
4040

41-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation
41+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
4242
SELECT aisle FROM supermarket WHERE person = 'matilda' FOR UPDATE
4343

4444
statement ok
@@ -51,7 +51,7 @@ SET CLUSTER SETTING sql.txn.snapshot_isolation.enabled = true
5151
statement ok
5252
BEGIN TRANSACTION ISOLATION LEVEL SNAPSHOT
5353

54-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under Snapshot isolation
54+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
5555
SELECT aisle FROM supermarket WHERE person = 'matilda' FOR UPDATE
5656

5757
statement ok
@@ -67,7 +67,7 @@ BEGIN TRANSACTION
6767
statement ok
6868
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
6969

70-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation
70+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
7171
UPDATE supermarket
7272
SET aisle = (SELECT aisle FROM supermarket WHERE person = 'matilda' FOR UPDATE)
7373
WHERE person = 'michael'
@@ -82,7 +82,7 @@ BEGIN TRANSACTION
8282
statement ok
8383
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
8484

85-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation
85+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
8686
WITH s AS
8787
(SELECT aisle FROM supermarket WHERE person = 'matilda' FOR UPDATE)
8888
SELECT aisle + 1 FROM s
@@ -99,7 +99,7 @@ statement ok
9999
SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED
100100

101101
# But calling that function should fail.
102-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation
102+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
103103
INSERT INTO supermarket (person, aisle) VALUES ('grandma', wrangle('matilda'))
104104

105105
statement ok
@@ -116,14 +116,14 @@ statement ok
116116
PREPARE psa AS SELECT aisle FROM supermarket WHERE person = $1::STRING FOR UPDATE
117117

118118
# But execution should fail.
119-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation
119+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
120120
EXECUTE psa('matilda')
121121

122122
statement ok
123123
DEALLOCATE psa
124124

125125
# SELECT FOR UPDATE using a lookup join should also fail.
126-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation
126+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
127127
WITH names AS MATERIALIZED
128128
(SELECT 'matilda' AS person)
129129
SELECT aisle
@@ -132,14 +132,14 @@ SELECT aisle
132132
FOR UPDATE
133133

134134
# SELECT FOR UPDATE using an index join should also fail.
135-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation
135+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
136136
SELECT aisle
137137
FROM supermarket@supermarket_starts_with_idx
138138
WHERE starts_with = 'm'
139139
FOR UPDATE
140140

141141
# SELECT FOR UPDATE using a zigzag join should also fail.
142-
query error pgcode 0A000 cannot execute SELECT FOR UPDATE statements under ReadCommitted isolation
142+
query error pgcode 0A000 guaranteed-durable locking not yet implemented
143143
SELECT aisle
144144
FROM supermarket@{FORCE_ZIGZAG}
145145
WHERE starts_with = 'm' AND ends_with = 'lda'

pkg/sql/opt/exec/execbuilder/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ go_library(
1414
importpath = "github.com/cockroachdb/cockroach/pkg/sql/opt/exec/execbuilder",
1515
visibility = ["//visibility:public"],
1616
deps = [
17-
"//pkg/kv/kvserver/concurrency/isolation",
1817
"//pkg/server/telemetry",
1918
"//pkg/sql/catalog/colinfo",
2019
"//pkg/sql/catalog/descpb",

pkg/sql/opt/exec/execbuilder/relational.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"math"
1818
"strings"
1919

20-
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/isolation"
2120
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
2221
"github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo"
2322
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
@@ -2901,11 +2900,9 @@ func (b *Builder) buildLocking(locking opt.Locking) (opt.Locking, error) {
29012900
"cannot execute %s in a read-only transaction", locking.Strength.String(),
29022901
)
29032902
}
2904-
if locking.Durability == tree.LockDurabilityGuaranteed &&
2905-
b.evalCtx.TxnIsoLevel != isolation.Serializable {
2903+
if locking.Durability == tree.LockDurabilityGuaranteed {
29062904
return opt.Locking{}, unimplemented.NewWithIssuef(
2907-
100144, "cannot execute SELECT FOR UPDATE statements under %s isolation",
2908-
b.evalCtx.TxnIsoLevel,
2905+
100193, "guaranteed-durable locking not yet implemented",
29092906
)
29102907
}
29112908
b.ContainsNonDefaultKeyLocking = true

0 commit comments

Comments
 (0)