Re: A few patches to clarify snapshot management, part 2 - Mailing list pgsql-hackers

From Álvaro Herrera
Subject Re: A few patches to clarify snapshot management, part 2
Date
Msg-id 202601051648.6qlcg46owpjm@alvherre.pgsql
Whole thread Raw
In response to Re: A few patches to clarify snapshot management, part 2  (Heikki Linnakangas <hlinnaka@iki.fi>)
Responses Re: A few patches to clarify snapshot management, part 2
List 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/



pgsql-hackers by date:

Previous
From: Jacob Champion
Date:
Subject: Re: DOCS - Clarify the publication 'publish_via_partition_root' default value.
Next
From: Florents Tselai
Date:
Subject: Re: Docs pg_restore: Shouldn't there be a note about -n ?