pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Increment xactCompletionCount during subtransaction abort.
Date: Tue, 06 Apr 2021 16:27:29 +0000
Message-ID: <E1lToY5-00080O-0I@gemulon.postgresql.org> (raw)

Increment xactCompletionCount during subtransaction abort.

Snapshot caching, introduced in 623a9ba79b, did not increment
xactCompletionCount during subtransaction abort. That could lead to an older
snapshot being reused. That is, at least as far as I can see, not a
correctness issue (for MVCC snapshots there's no difference between "in
progress" and "aborted"). The only difference between the old and new
snapshots would be a newer ->xmax.

While HeapTupleSatisfiesMVCC makes the same visibility determination, reusing
the old snapshot leads HeapTupleSatisfiesMVCC to not set
HEAP_XMIN_INVALID. Which subsequently causes the kill_prior_tuple optimization
to not kick in (via HeapTupleIsSurelyDead() returning false). The performance
effects of doing the same index-lookups over and over again is how the issue
was discovered...

Fix the issue by incrementing xactCompletionCount in
XidCacheRemoveRunningXids. It already acquires ProcArrayLock exclusively,
making that an easy proposition.

Add a test to ensure that kill_prior_tuple prevents index growth when it
involves aborted subtransaction of the current transaction.

Author: Andres Freund
Discussion: https://postgr.es/m/20210406043521.lopeo7bbigad3n6t@alap3.anarazel.de
Discussion: https://postgr.es/m/20210317055718.v6qs3ltzrformqoa%40alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/90c885cdab8bc5a5f12a243774fa0db51002a2fd

Modified Files
--------------
src/backend/storage/ipc/procarray.c |  8 +++++++
src/test/regress/expected/mvcc.out  | 42 +++++++++++++++++++++++++++++++++++
src/test/regress/parallel_schedule  |  2 +-
src/test/regress/serial_schedule    |  1 +
src/test/regress/sql/mvcc.sql       | 44 +++++++++++++++++++++++++++++++++++++
5 files changed, 96 insertions(+), 1 deletion(-)



Message-ID: <E1lToY5-00080O-0I@gemulon.postgresql.org>
Permalink:  ../E1lToY5-00080O-0I@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1lToY5-00080O-0I@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: pgsql: Increment xactCompletionCount during subtransaction abort.
  In-Reply-To: <E1lToY5-00080O-0I@gemulon.postgresql.org>
  References: <E1lToY5-00080O-0I@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox