Re: A new C function `get_partition_root`.

From: Peter Smith <smithpb2250(at)gmail(dot)com>
To: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: A new C function `get_partition_root`.
Date: 2026-07-29 08:58:00
Message-ID: CAHut+Pu9H7JEqR74QotL53xbL-A9Pc=54nQnpGMt7F+5S9Wm9g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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?

> 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 Content-Type Size
v3-0001-Add-C-function-get_partition_root.patch application/octet-stream 4.4 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2026-07-29 09:17:52 Re: A new C function `get_partition_root`.
Previous Message Michael Banck 2026-07-29 08:46:11 Re: Add statistics refresh materialized view