Re: A few patches to clarify snapshot management

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: A few patches to clarify snapshot management
Date: 2025-01-07 09:55:00
Message-ID: 0cc21d6a-32c4-4d34-9eeb-7a0cf6dca9e8@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 07/01/2025 00:00, Andres Freund wrote:
> On 2024-12-20 19:31:01 +0200, Heikki Linnakangas wrote:
>> While playing around some more with this, I noticed that this code in
>> GetTransactionSnapshot() is never reached, and AFAICS has always been dead
>> code:
>>
>>> Snapshot
>>> GetTransactionSnapshot(void)
>>> {
>>> /*
>>> * Return historic snapshot if doing logical decoding. We'll never need a
>>> * non-historic transaction snapshot in this (sub-)transaction, so there's
>>> * no need to be careful to set one up for later calls to
>>> * GetTransactionSnapshot().
>>> */
>>> if (HistoricSnapshotActive())
>>> {
>>> Assert(!FirstSnapshotSet);
>>> return HistoricSnapshot;
>>> }
>>
>> when you think about it, that's good, because it doesn't really make sense
>> to call GetTransactionSnapshot() during logical decoding. We jump through
>> hoops to make the historic catalog decoding possible with historic
>> snapshots, tracking subtransactions that modify catalogs and WAL-logging
>> command ids, but they're not suitable for general purpose queries. So I
>> think we should turn that into an error, per attached patch.
>
> Hm. I'm not sure it's a good idea to forbid this. Couldn't there be sane C
> code in an output functions calling GetTransactionSnapshot() or such to do
> some internal lookups?

I haven't seen any. And I don't think that would work correctly while
doing logical decoding anyway, because historical snapshots only track
XIDs that modify catalogs. regclassout and enumout do work because they
use the catalog snapshot rather than GetTransactionSnapshot().

(I committed that change in commit 1585ff7387 already, but discussion is
still welcome of course)

--
Heikki Linnakangas
Neon (https://neon.tech)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Maxim Orlov 2025-01-07 10:23:59 Re: POC: make mxidoff 64 bits
Previous Message Cédric Villemain 2025-01-07 09:47:42 Re: PoC: history of recent vacuum/checkpoint runs (using new hooks)