Re: SQL:2023 JSON simplified accessor support

From: Alexandra Wang <alexandra(dot)wang(dot)oss(at)gmail(dot)com>
To: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, Nikita Malakhov <hukutoc(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, Mark Dilger <mark(dot)dilger(at)enterprisedb(dot)com>, Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Peter Eisentraut <peter(at)eisentraut(dot)org>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Nikita Glukhov <glukhov(dot)n(dot)a(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, "David E(dot) Wheeler" <david(at)justatheory(dot)com>
Subject: Re: SQL:2023 JSON simplified accessor support
Date: 2025-09-03 02:16:37
Message-ID: CAK98qZ1XFee_x1uQFcwJkZCSVcPBy-A1ib3N5Ls2uDdZviKVOw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Chao,

Thanks for reviewing! I've attached v15, which addresses your
feedback.

I didn't make all the changes you suggested, please see my individual
comments below and in the next email.

On Mon, Sep 1, 2025 at 7:59 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:

> --- a/src/backend/parser/parse_node.c
> +++ b/src/backend/parser/parse_node.c
> @@ -244,7 +244,7 @@ transformContainerSubscripts(ParseState *pstate,
> Node
> *containerBase,
> Oid containerType,
> int32
> containerTypMod,
> - List *indirection,
> + List
> **indirection,
> bool isAssignment)
> {
> SubscriptingRef *sbsref;
> @@ -280,7 +280,7 @@ transformContainerSubscripts(ParseState *pstate,
> * element. If any of the items are slice specifiers
> (lower:upper), then
> * the subscript expression means a container slice operation.
> */
> - foreach(idx, indirection)
> + foreach(idx, *indirection)
> {
> A_Indices *ai = lfirst_node(A_Indices, idx);
>
> Should this foreach be pull up to out of transformContainerSubscripts()?
> Originally transformContainerSubscripts() runs only once, but now it’s
> placed in a while loop, and every time this foreach needs to go through the
> entire indirection list, which are duplicated computation.
>
>
> After revisiting the code, I think this loop of checking is_slice should
> be removed here.
>
> It seems only arrsubs cares about this is_slice flag.
>
> hstore_subs can only take a single indirection, so it can do a simple
> check like:
>
> ```
> ai = initial_node(A_Indices, *indirection);
> If (list_length(*indirection) != 1 || ai->is_slice)
> {
> ereport(…)
> }
> ```
>
> jsonbsubs doesn’t need to check is_slice flag as well, I will explain that
> in my next email tougher with my new comments.
>
> So that, “bool isSlace” can be removed from SubscriptTransform, and let
> every individual subs check is_slice.
>

I don't like the idea of removing the "bool isSlice" argument from the
*SubscriptTransform() function pointer. This patch series should make
only minimal changes to the subscripting API. While it's true that
each implementation can easily determine the boolean value of isSlice
itself, I don't see a clear benefit to changing the interface. As you
noted, arrsubs cares about isSlice; and users can also define custom
data types that support subscripting, so the interface is not limited
to built-in types.

As the comment for *SubscriptTransform() explains:

> (Of course, if the transform method
> * does not care to support slicing, it can just throw an error if isSlice.)

It's possible that in the end the "isSlice" argument isn't needed at
all, but I don’t think this patch set is the right place for that
refactor.

Best,
Alex

Attachment Content-Type Size
v15-0007-Implement-jsonb-wildcard-member-accessor.patch application/octet-stream 31.4 KB
v15-0001-Allow-transformation-of-only-a-sublist-of-subscr.patch application/octet-stream 9.0 KB
v15-0004-Extract-coerce_jsonpath_subscript.patch application/octet-stream 5.8 KB
v15-0006-Implement-Jsonb-subscripting-with-slicing.patch application/octet-stream 18.2 KB
v15-0005-Implement-read-only-dot-notation-for-jsonb.patch application/octet-stream 63.1 KB
v15-0003-Export-jsonPathFromParseResult.patch application/octet-stream 2.7 KB
v15-0002-Allow-Generic-Type-Subscripting-to-Accept-Dot-No.patch application/octet-stream 10.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexandra Wang 2025-09-03 02:20:53 Re: SQL:2023 JSON simplified accessor support
Previous Message Peter Smith 2025-09-03 01:57:42 Re: Add support for specifying tables in pg_createsubscriber.