Re: SQL:2023 JSON simplified accessor support

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Alexandra Wang <alexandra(dot)wang(dot)oss(at)gmail(dot)com>
Cc: 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-06-27 02:09:28
Message-ID: CACJufxFk7POVLuoJAzjsqywxy-4AJ6j2a0+A9fdo2eH5PM8EkQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.

in gram.y we have:
indirection_el:
'.' attr_name
{
$$ = (Node *) makeString($2);
}

we can be sure that dot notation, following dot is a plain string.
then in jsonb_subscript_transform, we can transform the String Node to
a TEXTOID Const.
with that, most of the
v11-0005-Enable-String-node-as-field-accessors-in-generic.patch
would be unnecessary.
Also in v11-0006-Implement-read-only-dot-notation-for-jsonb.patch
all these with pattern
``if (IsA(expr, String)``
can be removed.

in transformContainerSubscripts we have:
sbsref = makeNode(SubscriptingRef);
sbsref->refcontainertype = containerType;
sbsref->refelemtype = elementType;
sbsref->reftypmod = containerTypMod;
sbsref->refexpr = (Expr *) containerBase;
sbsref->refassgnexpr = NULL; /* caller will fill if it's an assignment */
sbsroutines->transform(sbsref, indirection, pstate,
isSlice, isAssignment);

then jsonb_subscript_transform we have
sbsref->refjsonbpath =
jsonb_subscript_make_jsonpath(pstate, indirection,
&sbsref->refupperindexpr,
&sbsref->reflowerindexpr);
of course sbsref->refupperindexpr, sbsref->reflowerindexpr is NIL
since we first called jsonb_subscript_make_jsonpath.

so we can simplify the function signature as
static void jsonb_subscript_make_jsonpath(pstate, indirection, sbsref)

Within jsonb_subscript_make_jsonpath we are going to populate
refupperindexpr, reflowerindexpr, refjsonbpath.

The attached patch addresses both of these issues, along with additional related
refactoring. It consolidates all the changes I think are appropriate, based on
patches v1-0001 to v1-0006. This will include patches previously I sent in
the earlier thread.

Attachment Content-Type Size
v11-0001-refactoring-v11_01-to-v11_06.no-cfbot application/octet-stream 17.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2025-06-27 02:22:27 RE: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly
Previous Message Yugo Nagata 2025-06-27 01:36:43 Re: Documentation fix on pgbench \aset command