Re: A new C function `get_partition_root`.

From: shveta malik <shveta(dot)malik(at)gmail(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, shveta malik <shveta(dot)malik(at)gmail(dot)com>
Subject: Re: A new C function `get_partition_root`.
Date: 2026-07-29 09:17:52
Message-ID: CAJpy0uBWmroik+xsxZ8oECigfacM4F766KS_E_Ur4iWKRRTJiw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jul 29, 2026 at 2:28 PM Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
>
> On Wed, Jul 29, 2026 at 3:23 PM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
> ...
> > 1)
> > CREATE TABLE p (id int);
> > CREATE TABLE c () INHERITS (p);
> >
> > select pg_partition_root('c') retruns NULL, while if we experiment
> > with get_partition_root('c') alone, it returns 'p'.
> >
> > The diffefrence in behaviour boils down to get_partition_ancestors()
> > returning valid ancestor list for 'c' (as you stated that this expects
> > caller to ensure input is a parition). So what do you suggest here?
> > More Assert in ' if (ancestors)' or leave it like this?
> >
>
> No need to leave as-is. The sanity check in the C function can be
> easily moved to cover this case too, so have done this.
>
> BTW, although I think using sanity Assert was correct, just in case
> there is some unanticipated way to reach the C function with a bad
> relid, I've changed to use an errlog(ERROR).
> Thoughts?

I don't immediately see any such possibility. I feel Assert is better.

> > 2)
> > - List *ancestors = get_partition_ancestors(relid);
> > + Oid root_relid = get_partition_root(relid);
> > const char *attname = get_attname(relid, attnum, false);
> >
> > - relid = llast_oid(ancestors);
> > + relid = root_relid;
> >
> > Should we get rid of root_relid and simply do:
> > relid = get_partition_root(relid);
> >
>
> Touché. Done as suggested.
>
> ~~~
>
> PSA patch v3.
>
> ======
> Kind Regards,
> Peter Smith.
> Fujitsu Australia

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-07-29 09:36:06 Re: Snapshot export on a standby corrupts hint bits on subxact overflow
Previous Message Peter Smith 2026-07-29 08:58:00 Re: A new C function `get_partition_root`.