pgsql: Fix serializable mode with index-only scans. - Mailing list pgsql-committers

From Kevin Grittner
Subject pgsql: Fix serializable mode with index-only scans.
Date
Msg-id E1T958o-0000Gn-NB@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix serializable mode with index-only scans.

Serializable Snapshot Isolation used for serializable transactions
depends on acquiring SIRead locks on all heap relation tuples which
are used to generate the query result, so that a later delete or
update of any of the tuples can flag a read-write conflict between
transactions.  This is normally handled in heapam.c, with tuple level
locking.  Since an index-only scan avoids heap access in many cases,
building the result from the index tuple, the necessary predicate
locks were not being acquired for all tuples in an index-only scan.

To prevent problems with tuple IDs which are vacuumed and re-used
while the transaction still matters, the xmin of the tuple is part of
the tag for the tuple lock.  Since xmin is not available to the
index-only scan for result rows generated from the index tuples, it
is not possible to acquire a tuple-level predicate lock in such
cases, in spite of having the tid.  If we went to the heap to get the
xmin value, it would no longer be an index-only scan.  Rather than
prohibit index-only scans under serializable transaction isolation,
we acquire an SIRead lock on the page containing the tuple, when it
was not necessary to visit the heap for other reasons.

Backpatch to 9.2.

Kevin Grittner and Tom Lane

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/cdf91edba9f92306b49afcc6bfa6be0e56eb0688

Modified Files
--------------
src/backend/executor/nodeIndexonlyscan.c        |   16 +++++++-
src/test/isolation/expected/index-only-scan.out |   41 ++++++++++++++++++++
src/test/isolation/isolation_schedule           |    1 +
src/test/isolation/specs/index-only-scan.spec   |   46 +++++++++++++++++++++++
4 files changed, 103 insertions(+), 1 deletions(-)


pgsql-committers by date:

Previous
From: Kevin Grittner
Date:
Subject: pgsql: Allow isolation tests to specify multiple setup blocks.
Next
From: Kevin Grittner
Date:
Subject: pgsql: Fix serializable mode with index-only scans.