Skip to content

Commit 76acbd4

Browse files
committed
logictest: add testcase for incorrect dupe key from UpdateSwap
In #145994 we discovered a problem with batch ordering that could cause the wrong ConditionFailed error to be returned. This could cause UpdateSwap and DeleteSwap to incorrectly return a duplicate key error instead of simply modifying 0 rows. This problem was fixed by #147117 and #147510. Now that we have UpdateSwap working, add a testcase that verifies the problem is fixed for UpdateSwap. Informs: #144503, #145994 Release note: None
1 parent 7fb2898 commit 76acbd4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

pkg/sql/logictest/testdata/logic_test/swap_mutation

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,58 @@ SELECT * FROM xyz ORDER BY x
125125
----
126126
1 1 11
127127
2 2 2
128+
129+
statement ok
130+
CREATE TABLE mno (m INT PRIMARY KEY, n INT, o INT NOT NULL, UNIQUE INDEX (o), INDEX (n), FAMILY (m, n, o))
131+
132+
statement ok
133+
INSERT INTO mno VALUES (3, 3, 3), (4, 4, 4)
134+
135+
statement error pq: duplicate key value violates unique constraint "mno_o_key"\nDETAIL: Key \(o\)=\(4\) already exists\.
136+
UPDATE mno SET o = 4 WHERE m = 3 AND n IS NOT DISTINCT FROM 3 AND o IS NOT DISTINCT FROM 3
137+
138+
query III
139+
SELECT * FROM mno ORDER BY m
140+
----
141+
3 3 3
142+
4 4 4
143+
144+
# The failure of the CPut of the primary index should trump the failure of the
145+
# CPut of the secondary index, meaning the end result should be 0 rows updated
146+
# instead of a dupe key error.
147+
statement ok
148+
UPDATE mno SET o = 4 WHERE m = 3 AND n IS NOT DISTINCT FROM 4 AND o IS NOT DISTINCT FROM 3
149+
150+
query III
151+
SELECT * FROM mno ORDER BY m
152+
----
153+
3 3 3
154+
4 4 4
155+
156+
statement ok
157+
ALTER TABLE mno ADD COLUMN p INT
158+
159+
statement ok
160+
ALTER TABLE mno DROP COLUMN p
161+
162+
statement error pq: duplicate key value violates unique constraint "mno_o_key"\nDETAIL: Key \(o\)=\(4\) already exists\.
163+
UPDATE mno SET o = 4 WHERE m = 3 AND n IS NOT DISTINCT FROM 3 AND o IS NOT DISTINCT FROM 3
164+
165+
query III
166+
SELECT * FROM mno ORDER BY m
167+
----
168+
3 3 3
169+
4 4 4
170+
171+
# Like above, even with the primary index ordered after the unique secondary
172+
# index, the failure of the CPut of the primary index should trump the failure
173+
# of the CPut of the secondary index, so the end result should be 0 rows updated
174+
# instead of a dupe key error.
175+
statement ok
176+
UPDATE mno SET o = 4 WHERE m = 3 AND n IS NOT DISTINCT FROM 4 AND o IS NOT DISTINCT FROM 3
177+
178+
query III
179+
SELECT * FROM mno ORDER BY m
180+
----
181+
3 3 3
182+
4 4 4

0 commit comments

Comments
 (0)