Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3ivr-006dF1-0i for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Sep 2026 23:39:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x3iuq-003AQJ-0A for pgsql-hackers@arkaria.postgresql.org; Mon, 07 Sep 2026 23:38:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3iup-003AQA-2R for pgsql-hackers@lists.postgresql.org; Mon, 07 Sep 2026 23:38:19 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x3iun-00000004VCy-2Xh9 for pgsql-hackers@lists.postgresql.org; Mon, 07 Sep 2026 23:38:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 687NcAP9460959; Mon, 7 Sep 2026 19:38:10 -0400 From: Tom Lane To: Zsolt Parragi cc: Chao Li , pgsql-hackers@lists.postgresql.org, Ewan Young Subject: Re: Introducing find_all_inheritors_ordered() In-reply-to: References: <57100518-3FF1-48AD-B550-47B9A3E88688@gmail.com> <20EAC3F9-81A2-41DD-89FA-1539EA8ED11B@gmail.com> Comments: In-reply-to Zsolt Parragi message dated "Mon, 07 Sep 2026 15:16:33 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <460957.1788824290.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 07 Sep 2026 19:38:10 -0400 Message-ID: <460958.1788824290@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Zsolt Parragi writes: > On Mon, 07 Sep 2026, Chao Li wrote: >> My understanding is that PG doesn=E2=80=99t intend to support cyclic in= heritance. 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). Why is it a valid scenario, and how would we reach it? It's going to cause tons of problems if it can happen, so I'd rather put effort into blocking it than making some parts of the system cope. I have a different concern about the patch as it stands: the data-gathering part is unnecessarily duplicative of find_all_inheritors. It does its best to look like it's doing something different, but actually it computes exactly the same list of relation OIDs and the same number-of-parents data. And indeed it had better be doing the same things in the same order, because otherwise we'd be risking deadlock failures instead of simple blocking when two processes are acquiring exclusive locks on overlapping inheritance trees. (Note the comment about "we need to be sure all backends lock children in the same order to avoid needless deadlocks" in find_inheritance_children.) I don't like having two independent implementations that are invisibly tied like that: if they diverge, we might not notice until somebody makes a bug report and somebody else figures out what's causing the deadlock. So IMO those two functions need to be revised to use a common data-gathering step. regards, tom lane