Re: Why are we restricting exported snapshots in subtransactions?

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Why are we restricting exported snapshots in subtransactions?
Date: 2017-06-13 17:15:57
Message-ID: CA+TgmoabAi2H_TmEQmVuZFZnetN+88kX75e2qQzORLCYoCAYVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jun 12, 2017 at 11:04 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> ExportSnapshot() has, right at the beginning, the following block:
>
> /*
> * We cannot export a snapshot from a subtransaction because there's no
> * easy way for importers to verify that the same subtransaction is still
> * running.
> */
> if (IsSubTransaction())
> ereport(ERROR,
> (errcode(ERRCODE_ACTIVE_SQL_TRANSACTION),
> errmsg("cannot export a snapshot from a subtransaction")));
>
> that reasoning doesn't seem to make too much sense to me. Given that
> exported snapshots don't make the exporting-transaction's changes
> visible, I don't see why that restriction is needed?
>
> As long as the exported snapshot enforces xmin to be retained, which it
> does via the pairingheap, I don't understand why we'd have to enforce
> that the subtransaction is still running?

I think you're touching on what is perhaps the key issue here, which
is that if it were possible to remove a tuple that the snapshot ought
to see before the snapshot got used, that would be bad. I don't
immediately see why we couldn't remove a tuple inserted by the aborted
subtransaction immediately. On a quick look, it seems to me that
HeapTupleSatisfiesVacuum() could fall through all the way to this
case:

/*
* Not in Progress, Not Committed, so either
Aborted or crashed
*/
SetHintBits(tuple, buffer, HEAP_XMIN_INVALID,
InvalidTransactionId);
return HEAPTUPLE_DEAD;

Even If I'm wrong about that, it seems like someone might want to make
me correct in the future - i.e. removing aborted tuples ASAP seems
like a good idea.

Another point to consider is whether a relfilenode assignment visible
to that snapshot might be a file that's since been truncated or
removed altogether.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2017-06-13 17:18:34 Announcing Release 5 of the PostgreSQL Buildfarm Client
Previous Message Bruce Momjian 2017-06-13 17:13:56 Re: WIP: Data at rest encryption