Re: Write skew observed under serializable isolation - Mailing list pgsql-hackers

From Zsolt Parragi
Subject Re: Write skew observed under serializable isolation
Date
Msg-id CAN4CZFOfQL_nOs2ukYf-CkcdP6EOQHu0dx2A+a90F+KDqajLKg@mail.gmail.com
Whole thread
In response to Re: Write skew observed under serializable isolation  (Aleksander Alekseev <aleksander@tigerdata.com>)
Responses Re: Write skew observed under serializable isolation
List pgsql-hackers
Hello!

-    /* one of SO_TYPE_* may be specified */
+    /*
+     * One of SO_TYPE_* may be specified.  When adding a scan type, check
+     * whether it must take predicate locks to be safe under SERIALIZABLE: see
+     * the flag test in heap_beginscan() and "Heap locking" in
+     * src/backend/storage/lmgr/README-SSI.
+     */

A wider llm-audit based on this claim pointed out that there's one
more preexisting issue: a tid scan that probes a tid holding no tuple
takes no predicate lock of any kind, so a concurrent INSERT that
materialises a tuple at exactly that TID creates no rw-conflict.

I'm not sure what's the proper solution for this, and if it even
should be part of this patch or something separate (as this patch is a
clear improvement even with this leftover issue), but it seems to be
at least worth a mention in a comment/commit message to state the
limitation?

An isolation test reproducing the problem:

setup
{
 create table ta (id int);
 insert into ta values (1), (2);
 create table tb (id int);
 insert into tb values (1), (2);
}
teardown { drop table ta; drop table tb; }

session s1
setup { begin isolation level serializable; set enable_seqscan = off; }
step r1 { select count(*) from tb where ctid = '(0,3)'; }
step w1 { insert into ta values (100); }
step c1 { commit; }

session s2
setup { begin isolation level serializable; set enable_seqscan = off; }
step r2 { select count(*) from ta where ctid = '(0,3)'; }
step w2 { insert into tb values (200); }
step c2 { commit; }

permutation r1 r2 w1 w2 c1 c2



pgsql-hackers by date:

Previous
From: Thom Brown
Date:
Subject: Re: REPACK (CONCURRENTLY) can silently lose updates when the toast table is rewritten
Next
From: Álvaro Herrera
Date:
Subject: Re: [PATCH] Misleading error message for REPACK USING INDEX on shared catalogs