On Wed, Jul 29, 2026 at 3:23 PM shveta malik <[email protected]> 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
v3-0001-Add-C-function-get_partition_root.patch
Description: Binary data
