Re: A new C function `get_partition_root`. - Mailing list pgsql-hackers

From Peter Smith
Subject Re: A new C function `get_partition_root`.
Date
Msg-id CAHut+Pu9H7JEqR74QotL53xbL-A9Pc=54nQnpGMt7F+5S9Wm9g@mail.gmail.com
Whole thread
In response to Re: A new C function `get_partition_root`.  (shveta malik <shveta.malik@gmail.com>)
List pgsql-hackers
On Wed, Jul 29, 2026 at 3:23 PM shveta malik <shveta.malik@gmail.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?

> 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

Attachment

pgsql-hackers by date:

Previous
From: Michael Banck
Date:
Subject: Re: Add statistics refresh materialized view
Next
From: Daniel Gustafsson
Date:
Subject: Re: [PATCH v1] Fix pg_basebackup long-path test on Windows