Re: Stale partition constraint on sub-partitions of a partitioned DEFAULT partition after a sibling is detached/dropped/created

From: Raja Sai pranav <rajasaipranav0(at)gmail(dot)com>
To: Michael Ries <mries(at)salesforce(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Stale partition constraint on sub-partitions of a partitioned DEFAULT partition after a sibling is detached/dropped/created
Date: 2026-11-23 09:36:25
Message-ID: CAPHduZACw9OE16_G7PBjQMGf0FhGP7rwtAoqMXW05AmYtEKH=g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Nov 18, 2026, Michael Ries wrote:
> A leaf partition under a *partitioned* DEFAULT partition keeps its old
> cached partition constraint (rd_partcheck) after a sibling of that DEFAULT
> is detached, dropped, created or attached.

Thanks for the clear report. I can reproduce both cases on master: the
insert of (2, 0) fails after the detach, and after creating t0_p5 a row
with g = 5 can still be inserted into t0_m1_d and is then hidden by
pruning.

> Suggested fix: when invalidating the default partition's relcache because
a
> sibling's bounds changed, and the default is partitioned, also invalidate
all
> of its descendants (find_all_inheritors), as ATTACH does for the attached
table.

That is what the attached patch does. It adds a small helper,
invalidate_default_partition(), and uses it in the three places that
used to invalidate only the default partition: StorePartitionBound()
(CREATE ... PARTITION OF and ATTACH), DetachPartitionFinalize() and
heap_drop_with_catalog(). The helper locks the descendants with
AccessExclusiveLock, like the detach code already does for the
partitions of a detached partitioned table. In the CREATE case they are
already locked by check_default_partition_contents(). In the DROP and
DETACH cases this lock is new, so comments on that are welcome.

The patch adds a test to alter_table.sql next to the one from
d6f1e16c8fe. Without the code change the test fails at all three steps
(detach, drop, create). With it, the regress, isolation and pg_upgrade
tests pass. The patch also applies cleanly to REL_18_STABLE and
REL_17_STABLE, but I have only built and tested it on master.

Regards,
Sai Pranav

Attachment Content-Type Size
v1-0001-Invalidate-partitions-of-a-partitioned-default-pa.patch application/octet-stream 8.7 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Shlok Kyal 2026-11-23 10:00:47 Re: Logical replication commits duplicates in DEFERRABLE unique indexes
Previous Message Dilip Kumar 2026-11-23 06:08:32 Re: BUG #19892: Logical replication skips UPDATE/DELETE of rows with NULL in a hash-indexed subscriber column