Re: Introducing find_all_inheritors_ordered()

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Ewan Young <kdbase(dot)hack(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org, Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Subject: Re: Introducing find_all_inheritors_ordered()
Date: 2026-09-04 21:48:59
Message-ID: CAN4CZFNX_BPSKgkoUKf_2X6uUvUpd2CiGRYfj01Vgc8fd5GkTg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 04 Sep 2026, Ewan Young <kdbase(dot)hack(at)gmail(dot)com> wrote:
> - Kahn's algorithm implementation looks right.

Not entirely, the implementation assumes that the graph is a DAG with
an assert, which unfortunately isn't the case:

At src/backend/commands/tablecmds.c:17958-17964 (ATExecAddInherit)

This is not completely bulletproof because of race conditions: in
multi-level inheritance trees, someone else could concurrently be
making another inheritance link that closes the loop but does not join
either of the rels we have locked. ... find_all_inheritors() will
cope with circularity anyway, so don't sweat it too much."

This can be reproduced a parallel alter, e.g.:

With r->b, b->c, d->e already in place:
S1: begin; alter table d inherit c; -- AEL(d), SUE(c), AS(d,e)
S2: begin; alter table b inherit e; -- AEL(b), SUE(e), AS(b,c)
S1: commit;
S2: commit;

And then alters can either hit the

Assert(list_length(ordered) == list_length(agenda));

assertion in debug builds or end up with a inconsistent results in
release builds.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-09-04 21:58:11 Re: [PATCH] Fix getopt_long() argument handling and add tests
Previous Message Paul A Jungwirth 2026-09-04 21:40:07 Improve error message for multiple assignment via view with FOR PORTION OF