Re: BUG #17949: Adding an index introduces serialisation anomalies.
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: Dmitry Dolgov <9erthalion6@gmail.com>
Cc: artem.anisimov.255@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2023-06-20T01:22:19Z
Lists: pgsql-bugs
Attachments
- v2-0001-Fix-race-in-SSI-interaction-with-empty-btrees.patch (text/x-patch) patch v2-0001
- v2-0002-Fix-race-in-SSI-interaction-with-bitmap-heap-scan.patch (text/x-patch) patch v2-0002
- test-ssi-gin-repro.c (text/x-csrc)
On Tue, Jun 20, 2023 at 12:18 AM Dmitry Dolgov <9erthalion6@gmail.com> wrote: > > On Mon, Jun 19, 2023 at 09:30:12PM +1200, Thomas Munro wrote: > > +#if 0 > > /* > > * Ignore any claimed entries past what we think is the end of the > > * relation. It may have been extended after the start of our scan (we > > * only hold an AccessShareLock, and it could be inserts from this > > * backend). > > */ > > if (block >= hscan->rs_nblocks) > > return false; > > +#endif > > Great, thanks! Can confirm, after applying both the posted patch and the > change above the issue is not reproducible anymore. Here's a cleaned-up version of the first two changes. What do you think about the assertions I make in the commit message for 0002? > One thing I've noticed is that one can observe a similar issue using a > gin index and int[] for the "path" column, even applying changes from > the thread. The gin implementation does something similar to btree in > startScanEntry -- it lands in "No entry found" branch, but instead of > locking the relation it locks "the leaf page, to lock the place where > the entry would've been, had there been one". The similar fix retrying > ginFindLeafPage didn't solve the problem, even if locking the whole > relation instead, but maybe I'm missing something. Ouch. I would have to go and study gin's interlocking model, but one superficial bug I spotted is that ginget.c's collectMatchBitmap() calls PredicateLockPage(stack->buffer), where a block number is expected. I wish we had strong typedefs, to reject stuff like that at compile time. But fixing that alone isn't enough. In case someone who knows more about gin is interested in helping, I attach Artem's repro, modified to use gin.
Commits
-
Fix race in SSI interaction with bitmap heap scan.
- 814f3c8e4868 11.21 landed
- 17b8887c29e5 12.16 landed
- 8976ac5c5c00 13.12 landed
- 3f7d3a77e18d 14.9 landed
- ab265e98500b 15.4 landed
- bcc93a389ce3 17.0 landed
- d03d9a2614fd 16.0 landed
-
Fix race in SSI interaction with gin fast path.
- 13f127800fed 11.21 landed
- 255a925d333b 12.16 landed
- fc15473840bc 13.12 landed
- fb663f38790e 14.9 landed
- d34aa0a2f4f3 15.4 landed
- 126552c85c1c 17.0 landed
- 12529028a4e5 16.0 landed
-
Fix race in SSI interaction with empty btrees.
- 0048c3b51549 11.21 landed
- fe88497b4d0b 12.16 landed
- 8f705d7b9d01 13.12 landed
- ae6d536ed0dc 14.9 landed
- 0f275b0ee8e4 15.4 landed
- f9b7fc651a99 17.0 landed
- 0cb1fb2c9bf8 16.0 landed
-
Re-think predicate locking on GIN indexes.
- 0bef1c0678d9 11.0 cited