pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Heikki Linnakangas <hlinnakangas@vmware.com>
Cc: Mark Kirkwood <mark.kirkwood@catalyst.net.nz>
Cc: Simon Riggs <simon@2ndQuadrant.com>
Cc: Gavin Flower <gavinflower@archidevsys.co.nz>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: In progress INSERT wrecks plans on table
Date: Sun, 16 Jun 2013 12:59:55 -0400
Message-ID: <21750.1371401995@sss.pgh.pa.us> (raw)
In-Reply-To: <51BDD868.3020106@vmware.com>
References: <5179E77B.7050601@catalyst.net.nz>
	<5179ECC5.2010206@archidevsys.co.nz>
	<5179F259.3010509@catalyst.net.nz>
	<5179F5C6.8070702@archidevsys.co.nz>
	<5180E3C8.3010201@catalyst.net.nz>
	<2121.1367417215@sss.pgh.pa.us>
	<5181B80D.70404@catalyst.net.nz>
	<CA+U5nMKYYZDekhtxz1E1B11dAm9UJoHBQHrB6DiiZDJo3fLd0Q@mail.gmail.com>
	<916bff05a5ab130c76d7835abbaf7762.squirrel@mail.catalyst.net.nz>
	<CA+U5nMJHjQccVSB3SkAHdRn2AfuuO49wA8-ZGB366cddTynjdQ@mail.gmail.com>
	<CA+U5nMKMfZUEimZ9=oF2wJ-WkiGhMw3mQjUFT6PBGofUpmXL8A@mail.gmail.com>
	<51870CB6.6090404@catalyst.net.nz>
	<51BDD868.3020106@vmware.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Heikki Linnakangas <hlinnakangas@vmware.com> writes:
> I'm not sure if this the same idea as (3) above, but ISTM that 
> HeapTupleSatisfiesMVCC doesn't actually need to call 
> TransactionIdIsInProgress(), because it checks XidInMVCCSnapshot(). The 
> comment at the top of tqual.c says:

>> * NOTE: must check TransactionIdIsInProgress (which looks in PGXACT array)
>> * before TransactionIdDidCommit/TransactionIdDidAbort (which look in
>> * pg_clog).  Otherwise we have a race condition: we might decide that a
>> * just-committed transaction crashed, because none of the tests succeed.
>> * xact.c is careful to record commit/abort in pg_clog before it unsets
>> * MyPgXact->xid in PGXACT array.  That fixes that problem, but it also
>> * means there is a window where TransactionIdIsInProgress and
>> * TransactionIdDidCommit will both return true.  If we check only
>> * TransactionIdDidCommit, we could consider a tuple committed when a
>> * later GetSnapshotData call will still think the originating transaction
>> * is in progress, which leads to application-level inconsistency.	The
>> * upshot is that we gotta check TransactionIdIsInProgress first in all
>> * code paths, except for a few cases where we are looking at
>> * subtransactions of our own main transaction and so there can't be any
>> * race condition.

> If TransactionIdIsInProgress() returns true for a given XID, then surely 
> it was also running when the snapshot was taken (or had not even began 
> yet). In which case the XidInMVCCSnapshot() call will also return true. 
> Am I missing something?

Yes, you're failing to understand the nature of the race condition.
What we're concerned about is that if tqual says a tuple is committed,
its transaction must be committed (not still in progress) according to
any *subsequently taken* snapshot.  This is not about the contents of
the snapshot we're currently consulting; it's about not wanting a tuple
to be thought committed if anyone could possibly later decide its
transaction is still in progress.

It's possible that this issue would be moot if the only use of
transaction-in-progress data were in tqual.c (so that we could assume
all later tests use the same logic you propose here), but I doubt that
that's true.

			regards, tom lane


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (42+ messages)  latest in thread

Message-ID: <21750.1371401995@sss.pgh.pa.us>
Permalink:  ../21750.1371401995@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21750.1371401995@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, hlinnakangas@vmware.com, mark.kirkwood@catalyst.net.nz, simon@2ndQuadrant.com, gavinflower@archidevsys.co.nz
  Subject: Re: In progress INSERT wrecks plans on table
  In-Reply-To: <21750.1371401995@sss.pgh.pa.us>

* 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