Skip to content

Commit 0b1d979

Browse files
committed
sql: only use side-effect splitter if locking durability = guaranteed
The span splitter has an optimization to skip reading column families whose columns are contained entirely in the index key. In #116170 we added a flag to the span splitter to ignore this optimization when the read has a side-effect (i.e. it's a locking read). The intention of #116170 was to ensure that SELECT FOR UPDATE statements under Read Committed isolation lock all requested column families. But the span splitter flag also applies to the implicit for-update locking added to mutation statements. This was not intentional. The implicit for-update locking added to mutation statements is not needed for correctness, but is supposed to be a lightweight optimization to prevent retries of racing write-write conflicts. The implicit for-update locking is already not durable. It's fine if it does not lock every requested column family. This commit changes the decision about whether to use the span splitter optimization to depend on the locking durability, rather than the isolation level. This extends the meaning of locking durability slightly, but I think it fits within the semantics of best effort = the requested lock might not actually be held. This should fix the YCSB regression under Read Committed isolation. Fixes: #143138 Release note: None
1 parent 74c7286 commit 0b1d979

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

pkg/ccl/logictestccl/testdata/logic_test/read_committed

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,40 @@ statement ok
594594
ROLLBACK;
595595

596596
subtest end
597+
598+
subtest regression_143138
599+
600+
statement ok
601+
CREATE TABLE usertable (
602+
ycsb_key VARCHAR(255) NOT NULL,
603+
field0 STRING NOT NULL,
604+
field1 STRING NOT NULL,
605+
CONSTRAINT usertable_pkey PRIMARY KEY (ycsb_key ASC),
606+
FAMILY fam_0_ycsb_key (ycsb_key),
607+
FAMILY fam_1_field0 (field0),
608+
FAMILY fam_2_field1 (field1)
609+
)
610+
611+
statement ok
612+
SET plan_cache_mode = force_generic_plan
613+
614+
statement ok
615+
PREPARE p AS UPDATE usertable SET field1 = $2:::STRING WHERE ycsb_key = $1:::STRING;
616+
617+
query T kvtrace
618+
EXECUTE p ('foo', 'bar')
619+
----
620+
Scan /Table/119/1/"foo"/2/1 lock Exclusive (Block, Unreplicated)
621+
622+
statement ok
623+
BEGIN ISOLATION LEVEL READ COMMITTED;
624+
625+
query T kvtrace
626+
EXECUTE p ('foo', 'bar')
627+
----
628+
Scan /Table/119/1/"foo"/2/1 lock Exclusive (Block, Unreplicated)
629+
630+
statement ok
631+
ROLLBACK
632+
633+
subtest end

pkg/sql/distsql_physical_planner.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"github.com/cockroachdb/cockroach/pkg/kv"
2222
"github.com/cockroachdb/cockroach/pkg/kv/kvclient"
2323
"github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord"
24-
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency/isolation"
2524
"github.com/cockroachdb/cockroach/pkg/roachpb"
2625
"github.com/cockroachdb/cockroach/pkg/rpc"
2726
"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"
@@ -3460,7 +3459,7 @@ func (dsp *DistSQLPlanner) planLookupJoin(
34603459

34613460
var splitter span.Splitter
34623461
if joinReaderSpec.LockingStrength != descpb.ScanLockingStrength_FOR_NONE &&
3463-
planCtx.ExtendedEvalCtx.TxnIsoLevel != isolation.Serializable {
3462+
joinReaderSpec.LockingDurability == descpb.ScanLockingDurability_GUARANTEED {
34643463
splitter = span.MakeSplitterForSideEffect(planInfo.fetch.desc, planInfo.fetch.index, fetchOrdinals)
34653464
} else {
34663465
splitter = span.MakeSplitter(planInfo.fetch.desc, planInfo.fetch.index, fetchOrdinals)

0 commit comments

Comments
 (0)