You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Previously, the speculative insert tests did not cover the case when atuple t is inserted into a table with a unique index on a column butbefore it can insert into the index, a concurrent transaction hasinserted a conflicting value into the index and the insertion of tuple tmust be aborted.The basic permutation is one session successfully inserts into the tableand an associated unique index while a concurrent session successfullyinserts into the table but discovers a conflict before inserting intothe index and must abort the insertion.Several variants on this include:- swap which session is successful- first session insert transaction does not commit, so second sessionmust wait on a transaction lock- first session insert does not "complete", so second session must waiton a speculative insertion lockAlso, refactor the existing TOAST table upsert test to be in the samespec and reuse the steps.Author: Melanie Plageman, Ashwin Agrawal, Andres FreundReviewed-by: Andres Freund, Taylor VeselyDiscussion:https://postgr.es/m/CAAKRu_ZRmxy_OEryfY3G8Zp01ouhgw59_-_Cm8n7LzRH5BAvng@mail.gmail.com
step s1_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s1') ON CONFLICT (blurt_and_lock(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s1'; <waiting ...>
19
-
s2: NOTICE: called for k1
20
-
s2: NOTICE:blocking 3
21
-
step s2_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; <waiting ...>
16
+
s1: NOTICE:blurt_and_lock_123()called for k1 in session 1
17
+
s1: NOTICE:acquiring advisory lock on 3
18
+
step s1_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s1') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s1'; <waiting ...>
19
+
s2: NOTICE:blurt_and_lock_123()called for k1 in session 2
20
+
s2: NOTICE:acquiring advisory lock on 3
21
+
step s2_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; <waiting ...>
s1: NOTICE:blurt_and_lock_123()called for k1 in session 1
62
+
s1: NOTICE:acquiring advisory lock on 2
63
+
s1: NOTICE:blurt_and_lock_123()called for k1 in session 1
64
+
s1: NOTICE:acquiring advisory lock on 2
65
65
step s1_upsert: <... completed>
66
66
step controller_show: SELECT * FROM upserttest;
67
67
key data
@@ -81,12 +81,12 @@ pg_advisory_locksess lock
81
81
step controller_show: SELECT * FROM upserttest;
82
82
key data
83
83
84
-
s1: NOTICE: called for k1
85
-
s1: NOTICE:blocking 3
86
-
step s1_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s1') ON CONFLICT (blurt_and_lock(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s1'; <waiting ...>
87
-
s2: NOTICE: called for k1
88
-
s2: NOTICE:blocking 3
89
-
step s2_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; <waiting ...>
84
+
s1: NOTICE:blurt_and_lock_123()called for k1 in session 1
85
+
s1: NOTICE:acquiring advisory lock on 3
86
+
step s1_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s1') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s1'; <waiting ...>
87
+
s2: NOTICE:blurt_and_lock_123()called for k1 in session 2
88
+
s2: NOTICE:acquiring advisory lock on 3
89
+
step s2_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; <waiting ...>
step s1_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s1') ON CONFLICT (blurt_and_lock(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s1'; <waiting ...>
157
-
s2: NOTICE: called for k1
158
-
s2: NOTICE:blocking 3
159
-
step s2_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; <waiting ...>
222
+
s1: NOTICE:blurt_and_lock_123()called for k1 in session 1
223
+
s1: NOTICE:acquiring advisory lock on 3
224
+
step s1_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s1') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s1'; <waiting ...>
225
+
s2: NOTICE:blurt_and_lock_123()called for k1 in session 2
226
+
s2: NOTICE:acquiring advisory lock on 3
227
+
step s2_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; <waiting ...>
s1: NOTICE: blurt_and_lock_123() called for k1 in session 1
307
+
s1: NOTICE: acquiring advisory lock on 3
308
+
step s1_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s1') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s1'; <waiting ...>
309
+
s2: NOTICE: blurt_and_lock_123() called for k1 in session 2
310
+
s2: NOTICE: acquiring advisory lock on 3
311
+
step s2_upsert: INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; <waiting ...>