Re: A few patches to clarify snapshot management, part 2

From: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: Andres Freund <andres(at)anarazel(dot)de>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Subject: Re: A few patches to clarify snapshot management, part 2
Date: 2026-01-05 17:01:12
Message-ID: 202601051648.6qlcg46owpjm@alvherre.pgsql
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2025-Dec-22, Heikki Linnakangas wrote:

> @@ -146,7 +146,11 @@ find_inheritance_children_extended(Oid parentrelId, bool omit_detached,
> Snapshot snap;
>
> xmin = HeapTupleHeaderGetXmin(inheritsTuple->t_data);
> +
> + /* XXX: what should we do with a non-MVCC snapshot? */
> snap = GetActiveSnapshot();
> + if (snap->snapshot_type != SNAPSHOT_MVCC)
> + elog(ERROR, "cannot look up partition information with a non-MVCC snapshot");
>
> if (!XidInMVCCSnapshot(xmin, snap))
> {

I think this code should be skipped when a non-MVCC snapshot is in use.
I assume you won't hit the case unless you test for it specifically, so
I'm not surprised that just adding an elog(ERROR) does not cause visible
failures; however in production it probably would. And looking up
partition info in that case is, most likely, useless. So changing the
'if' test
if (!XidInMVCCSnapshot(xmin, snap))
to only do this dance if "->snapshot_type == SNAPSHOT_MVCC" seems
reasonable to me.

I'm not sure what's a good way to verify this, however. We would need a
test that adds partitions pending detach to partitioned tables used by
as many other tests as possible ... (Maybe: have test_setup.sql add an
event trigger that runs on CREATE TABLE, detects PARTITION BY, and
creates and partially detaches a partition. Not sure how feasible this
is.)

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Florents Tselai 2026-01-05 17:11:06 Re: Docs pg_restore: Shouldn't there be a note about -n ?
Previous Message Jacob Champion 2026-01-05 16:32:31 Re: DOCS - Clarify the publication 'publish_via_partition_root' default value.