From: Chao Li <li.evan.chao@gmail.com>
To: Zsolt Parragi <zsolt.parragi@percona.com>
Cc: pgsql-hackers@lists.postgresql.org, Ewan Young <kdbase.hack@gmail.com>
Subject: Re: Introducing find_all_inheritors_ordered()
Date: Tue, 8 Sep 2026 11:46:26 +0800
Message-ID: <478CC29D-1E62-4804-9FF0-C8E25E604FEE@gmail.com> (raw)
In-Reply-To: <CAN4CZFNZD-1_XcEA+BGAi9_KgqzuONzecyVsMu9sB1Xp8+gHkg@mail.gmail.com>
References: <57100518-3FF1-48AD-B550-47B9A3E88688@gmail.com>
<CAON2xHMcy+mr-bhZGT7cS3EzQWZ_Yc7OfTO+c9KV3SFacjfmfA@mail.gmail.com>
<CAN4CZFNX_BPSKgkoUKf_2X6uUvUpd2CiGRYfj01Vgc8fd5GkTg@mail.gmail.com>
<20EAC3F9-81A2-41DD-89FA-1539EA8ED11B@gmail.com>
<CAN4CZFNZD-1_XcEA+BGAi9_KgqzuONzecyVsMu9sB1Xp8+gHkg@mail.gmail.com>
> On Sep 8, 2026, at 06:16, Zsolt Parragi <zsolt.parragi@percona.com> wrote:
>
> On Mon, 07 Sep 2026, Chao Li <li.evan.chao@gmail.com> wrote:
>> My understanding is that PG doesn’t intend to support cyclic inheritance. The code explicitly rejects it:
>
> To me it seems like that it discourages it and tries to prevent it
> where it's possible to do so with reasonable effort, but it ends up
> trying to support it because it's a valid scenario that can happen in
> some workloads (as long as that also doesn't require too much effort).
I think an important problem is that, in your earlier example, two users independently execute ALTER TABLE … INHERIT, but the commands together create an inheritance cycle without either user being notified. Even if PG currently tolerates this, I think preventing it would be preferable.
As Tom pointed out, cycles can also cause problems elsewhere in the system. So I agree that we should investigate whether we can prevent their creation at a reasonable cost.
>
>> A cycle can cause it to exceed the stack depth limit, so it is reasonable to fail the command when a cycle is detected.
>
> Or it might succeed in other cases.
>
> Here's a repro with an isolation test. Perm 1 fails on master, works
> with the patch. Perm 2 works on master, fails with the patch.
> We could improve this by only using the new function in the enforced
> direction, I don't have a better idea currently. With that, the
> patched behavior would be the same as on master.
>
This is a valid point. ENFORCED doesn’t need to check parents’ enforceability, so we can still use find_all_inheritors() to tolerate potential cycles and use find_all_inheritors_ordered() only for NOT ENFORCED. This preserves master’s success/failure outcomes in your test, while replacing the stack-depth error with an explicit cycle error. I have updated the code in v3.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: li.evan.chao@gmail.com, zsolt.parragi@percona.com, kdbase.hack@gmail.com
Subject: Re: Introducing find_all_inheritors_ordered()
In-Reply-To: <478CC29D-1E62-4804-9FF0-C8E25E604FEE@gmail.com>
References: <57100518-3FF1-48AD-B550-47B9A3E88688@gmail.com> <CAON2xHMcy+mr-bhZGT7cS3EzQWZ_Yc7OfTO+c9KV3SFacjfmfA@mail.gmail.com> <CAN4CZFNX_BPSKgkoUKf_2X6uUvUpd2CiGRYfj01Vgc8fd5GkTg@mail.gmail.com> <20EAC3F9-81A2-41DD-89FA-1539EA8ED11B@gmail.com> <CAN4CZFNZD-1_XcEA+BGAi9_KgqzuONzecyVsMu9sB1Xp8+gHkg@mail.gmail.com> <478CC29D-1E62-4804-9FF0-C8E25E604FEE@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox