pgsql: Re-think predicate locking on GIN indexes.

From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Re-think predicate locking on GIN indexes.
Date: 2018-05-04 08:29:05
Message-ID: E1fEW5R-0004iu-9B@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Re-think predicate locking on GIN indexes.

The principle behind the locking was not very well thought-out, and not
documented. Add a section in the README to explain how it's supposed to
work, and change the code so that it actually works that way.

This fixes two bugs:

1. If fast update was turned on concurrently, subsequent inserts to the
pending list would not conflict with predicate locks that were acquired
earlier, on entry pages. The included 'predicate-gin-fastupdate' test
demonstrates that. To fix, make all scans acquire a predicate lock on
the metapage. That lock represents a scan of the pending list, whether
or not there is a pending list at the moment. Forget about the
optimization to skip locking/checking for locks, when fastupdate=off.
2. If a scan finds no match, it still needs to lock the entry page. The
point of predicate locks is to lock the gabs between values, whether
or not there is a match. The included 'predicate-gin-nomatch' test
tests that case.

In addition to those two bug fixes, this removes some unnecessary locking,
following the principle laid out in the README. Because all items in
a posting tree have the same key value, a lock on the posting tree root is
enough to cover all the items. (With a very large posting tree, it would
possibly be better to lock the posting tree leaf pages instead, so that a
"skip scan" with a query like "A & B", you could avoid unnecessary conflict
if a new tuple is inserted with A but !B. But let's keep this simple.)

Also, some spelling fixes.

Author: Heikki Linnakangas with some editorization by me
Review: Andrey Borodin, Alexander Korotkov
Discussion: https://www.postgresql.org/message-id/0b3ad2c2-2692-62a9-3a04-5724f2af9114@iki.fi

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0bef1c0678d94436f80450d562a866bb6fa5e509

Modified Files
--------------
src/backend/access/gin/README | 34 ++++++
src/backend/access/gin/ginbtree.c | 3 +
src/backend/access/gin/gindatapage.c | 7 +-
src/backend/access/gin/ginfast.c | 8 ++
src/backend/access/gin/ginget.c | 116 ++++++++++-----------
src/backend/access/gin/gininsert.c | 26 +----
src/backend/access/gin/ginutil.c | 7 --
src/backend/access/gin/ginvacuum.c | 1 -
src/backend/access/gist/gist.c | 2 +-
src/backend/storage/lmgr/README-SSI | 22 ++--
src/include/access/gin_private.h | 3 -
.../expected/predicate-gin-fastupdate.out | 30 ++++++
.../isolation/expected/predicate-gin-nomatch.out | 15 +++
src/test/isolation/expected/predicate-gin.out | 4 +-
src/test/isolation/isolation_schedule | 2 +
.../isolation/specs/predicate-gin-fastupdate.spec | 49 +++++++++
.../isolation/specs/predicate-gin-nomatch.spec | 35 +++++++
src/test/isolation/specs/predicate-gin.spec | 4 +-
18 files changed, 251 insertions(+), 117 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Teodor Sigaev 2018-05-04 09:38:45 pgsql: Don't truncate away non-key attributes for leftmost downlinks.
Previous Message Peter Eisentraut 2018-05-04 00:30:06 pgsql: Update expected files for older Python versions