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: Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Chao Li <li(dot)evan(dot)chao(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-16 08:17:19
Message-ID: CAHut+PtKRBLuDeJpQFz6Kio5vGLOPBaL=AxAQm=qRCFGTYCiZw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 3, 2026 at 8:15 PM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
> On Mon, Aug 3, 2026 at 2:34 PM Álvaro Herrera <alvherre(at)kurilemu(dot)de> wrote:
> >
> > Hi,
> >
> > I'd say this looks okay, but why do you need get_partition_root_guts()
> > exposed in partition.h? In fact, it's not clear to me why you need a
> > second routine at all. Why isn't enough to have just get_partition_root()?
> >
>
> I think to avoid performing the validation twice in
> pg_partition_root(): first via check_rel_can_be_partition(), and then
> again in get_partition_root (see [1]), get_partition_root_guts() is
> introduced and exposed in partition.h.
>
> [1]:
> + /* Validate relid is member of a partition tree */
> + Assert(get_rel_relispartition(relid) ||
> + RELKIND_HAS_PARTITIONS(get_rel_relkind(relid)));
>

PSA patch v7, which has the following changes:

1. The wrapped function get_partition_root_guts() is removed. It
previously existed in v6 only to avoid a double validation when called
from the SQL pg_partition_root() function. Now, we chose not to care
about double validation because the inner validation is Assert code,
so it only happens in DEBUG build anyhow.

3. The status validation function check_rel_can_be_partition() is now
common code so that it can be called from all places.

3. Similar validation (checking if relid can be part of a partition
tree) is now also done for the get_partition_ancestors() C function.
(Note: Existing code calls this function with RELKIND_INDEX/
RELKIND_PARTITIONED_INDEX, so the assertion is slightly different)

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

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexandre Felipe 2026-08-16 09:54:47 Re: [PATCH] bufmgr: tighten LWLock:BufferMapping on InvalidateBuffer
Previous Message Michael Paquier 2026-08-16 07:13:20 Re: Thread-safe stringToNode() / pg_strtok()