]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Use "concurrent delete" in serialization error for TM_Deleted cases
authorAmit Langote <amitlan@postgresql.org>
Fri, 1 May 2026 00:56:10 +0000 (09:56 +0900)
committerAmit Langote <amitlan@postgresql.org>
Fri, 1 May 2026 01:00:29 +0000 (10:00 +0900)
In ExecLockRows() and ri_LockPKTuple(), the TM_Deleted code path was
using the same "could not serialize access due to concurrent update"
message as the TM_Updated path.  Use "concurrent delete" instead, since
the tuple was deleted, not updated.  The ExecLockRows() instance was
likely a copy-paste error per Andres; the ri_LockPKTuple() instance
was carried over from the same pattern in commit 2da86c1ef9.

Update affected isolation test expected files accordingly and add
a new test to fk-concurrent-pk-upd.spec with concurrent delete of the
PK row.

The ExecLockRows() change is master-only for lack of user complaints
and to avoid breaking anything that might match on the error text.

Reported-by: Jian He <jian.universality@gmail.com>
Author: Amit Langote <amitlangote09@gmail.com>
Reviewed-by: Junwang Zhao <zhjwpku@gmail.com>
Discussion: https://postgr.es/m/CACJufxEG1JTCq4A1gnNAu-bGAq9Xn=Xkf7kC3TRWFz6iuUOuRA@mail.gmail.com

src/backend/executor/nodeLockRows.c
src/backend/utils/adt/ri_triggers.c
src/test/isolation/expected/fk-concurrent-pk-upd.out
src/test/isolation/expected/fk-partitioned-2.out
src/test/isolation/expected/fk-snapshot-2.out
src/test/isolation/expected/fk-snapshot-3.out
src/test/isolation/specs/fk-concurrent-pk-upd.spec

index 8d865470780eb5386bba279b40c285b19c6f1fa0..3bee818a8b47ab9109c91c1f397895bfa15af2ae 100644 (file)
@@ -234,7 +234,7 @@ lnext:
                                if (IsolationUsesXactSnapshot())
                                        ereport(ERROR,
                                                        (errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
-                                                        errmsg("could not serialize access due to concurrent update")));
+                                                        errmsg("could not serialize access due to concurrent delete")));
                                /* tuple was deleted so don't return it */
                                goto lnext;
 
index f63a7f0b580c97e2c0c8b53240236e0909fca511..dc89c6863946be21030971e1dde432219648dc44 100644 (file)
@@ -3244,7 +3244,7 @@ ri_LockPKTuple(Relation pk_rel, TupleTableSlot *slot, Snapshot snap,
                        if (IsolationUsesXactSnapshot())
                                ereport(ERROR,
                                                (errcode(ERRCODE_T_R_SERIALIZATION_FAILURE),
-                                                errmsg("could not serialize access due to concurrent update")));
+                                                errmsg("could not serialize access due to concurrent delete")));
                        return false;
 
                case TM_Updated:
index 4dd9535d3c0ba85f8aaa7ff67dcc4fa99e6d6b82..84937399249ff956545c49d2d861a1fd9b7f170e 100644 (file)
@@ -84,6 +84,26 @@ child_key|parent_key
 (0 rows)
 
 
+starting permutation: s2b s2dkey s3b s3i s2c s3c s2s s3s
+step s2b: BEGIN;
+step s2dkey: DELETE FROM parent WHERE parent_key = 1;
+step s3b: BEGIN ISOLATION LEVEL REPEATABLE READ;
+step s3i: INSERT INTO child VALUES (2, 1); <waiting ...>
+step s2c: COMMIT;
+step s3i: <... completed>
+ERROR:  could not serialize access due to concurrent delete
+step s3c: COMMIT;
+step s2s: SELECT * FROM parent;
+parent_key|aux
+----------+---
+(0 rows)
+
+step s3s: SELECT * FROM child;
+child_key|parent_key
+---------+----------
+(0 rows)
+
+
 starting permutation: s2b s2uaux s3b s3i s2c s3c s2s s3s
 step s2b: BEGIN;
 step s2uaux: UPDATE parent SET aux = 'bar' WHERE parent_key = 1;
index db621bee2d67ec9be82143705f289f9159eb2641..fd3d97c832f8aa27126e168e2a24cc2764f56275 100644 (file)
@@ -22,7 +22,7 @@ step s2bs: begin isolation level serializable; select 1;
 step s2i: insert into pfk values (1); <waiting ...>
 step s1c: commit;
 step s2i: <... completed>
-ERROR:  could not serialize access due to concurrent update
+ERROR:  could not serialize access due to concurrent delete
 step s2c: commit;
 
 starting permutation: s1b s2b s1d s2i s1c s2c
@@ -47,7 +47,7 @@ step s1d: delete from ppk where a = 1;
 step s2i: insert into pfk values (1); <waiting ...>
 step s1c: commit;
 step s2i: <... completed>
-ERROR:  could not serialize access due to concurrent update
+ERROR:  could not serialize access due to concurrent delete
 step s2c: commit;
 
 starting permutation: s1b s2b s2i s1d s2c s1c
index 0a4c9646fca4e6901d26fb41f8a6615f13190536..7333643e9ac2a57b88f1b40e40b8d4c13fec265e 100644 (file)
@@ -17,7 +17,7 @@ step s1del: DELETE FROM parent WHERE parent_id = 1;
 step s2ins: INSERT INTO child VALUES (1, 1); <waiting ...>
 step s1c: COMMIT;
 step s2ins: <... completed>
-ERROR:  could not serialize access due to concurrent update
+ERROR:  could not serialize access due to concurrent delete
 step s2c: COMMIT;
 
 starting permutation: s1rc s2rc s2ins s1del s2c s1c
@@ -57,5 +57,5 @@ step s1del: DELETE FROM parent WHERE parent_id = 1;
 step s2ins: INSERT INTO child VALUES (1, 1); <waiting ...>
 step s1c: COMMIT;
 step s2ins: <... completed>
-ERROR:  could not serialize access due to concurrent update
+ERROR:  could not serialize access due to concurrent delete
 step s2c: COMMIT;
index f98cb72fdac30739bccdd6ee21f13ce4423b7521..2dc490be48b5d60c02fca488a65468ee165a0723 100644 (file)
@@ -21,7 +21,7 @@ step s2ins:
  <waiting ...>
 step s1c: COMMIT;
 step s2ins: <... completed>
-ERROR:  could not serialize access due to concurrent update
+ERROR:  could not serialize access due to concurrent delete
 step s2c: COMMIT;
 
 starting permutation: s1rc s2rc s2ins s1del s2c s1c
@@ -69,7 +69,7 @@ step s2ins:
  <waiting ...>
 step s1c: COMMIT;
 step s2ins: <... completed>
-ERROR:  could not serialize access due to concurrent update
+ERROR:  could not serialize access due to concurrent delete
 step s2c: COMMIT;
 
 starting permutation: s1rc s2rc s2ins s1upok s2c s1c
index 03dc7f260cd693e5db24ace10c3eeac1d7ae4a0b..139c2b4d8c727426b52603796f673981f89caaca 100644 (file)
@@ -31,6 +31,7 @@ step s2b  { BEGIN; }
 step s2ukey { UPDATE parent SET parent_key = 2 WHERE parent_key = 1; }
 step s2uaux { UPDATE parent SET aux = 'bar' WHERE parent_key = 1; }
 step s2ukey2 { UPDATE parent SET parent_key = 1 WHERE parent_key = 2; }
+step s2dkey { DELETE FROM parent WHERE parent_key = 1; }
 step s2c { COMMIT; }
 step s2s { SELECT * FROM parent; }
 
@@ -49,5 +50,7 @@ permutation s2b s2ukey s1b s1i s2ukey2 s2c s1c s2s s1s
 
 # RR: key update -> serialization failure
 permutation s2b s2ukey s3b s3i s2c s3c s2s s3s
+# RR: key delete -> serialization failure
+permutation s2b s2dkey s3b s3i s2c s3c s2s s3s
 # RR: non-key update -> old version visible via transaction snapshot
 permutation s2b s2uaux s3b s3i s2c s3c s2s s3s