Re: A new C function `get_partition_root`.

From: Peter Smith <smithpb2250(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: shveta malik <shveta(dot)malik(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: A new C function `get_partition_root`.
Date: 2026-08-03 08:44:08
Message-ID: CAHut+PurLML6fnO=wPJJRjvsK=Mv_ZtOnJHWsNEpm4NNu=kXRg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 3, 2026 at 5:47 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>
...
>
> Thanks for updating the patch.
>
> Given the comment:
> ```
> + * Note: This should only be called when it is known that the relation is a
> + * partition or partitioned table.
> ```
>
> Does it make sense to add an Assert for that, like:
> ```
> Assert(get_rel_relispartition(relid) ||
> RELKIND_HAS_PARTITIONS(get_rel_relkind(relid)));
> ```
>
> Then, maybe we don’t need the final sanity check assert.
>
> Otherwise v5 looks good to me. The new parameter even_if_detached matches the existing get_partition_parent().
>

Until now I had been resisting doing up front validation because:
1. then the delegation from the SQL `pg_partition_root` would be doing
2x validation.
2. get_partition_ancestors was not doing any validation

Anyway, in v6 I've done the following:
1. changed to add a wrapper to avoid 2x validation when called from
the SQL function
2. decided not to worry about validation overheads because Assert is
NOP for a production build anyhow

~~

PSA v6

======
Kind Regards,
Peter Smith.
Fujitsu Australia

Attachment Content-Type Size
v6-0001-Add-C-function-get_partition_root.patch application/octet-stream 6.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-08-03 08:49:48 Fix NO_OOM handling in MemoryContextAllocAligned
Previous Message Peter Eisentraut 2026-08-03 08:33:13 Re: Fix missing space before WHERE in `GRAPH_TABLE` deparse