Re: SQL:2023 JSON simplified accessor support - Mailing list pgsql-hackers

From jian he
Subject Re: SQL:2023 JSON simplified accessor support
Date
Msg-id CACJufxFk7POVLuoJAzjsqywxy-4AJ6j2a0+A9fdo2eH5PM8EkQ@mail.gmail.com
Whole thread Raw
In response to Re: SQL:2023 JSON simplified accessor support  (Peter Eisentraut <peter@eisentraut.org>)
List 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

pgsql-hackers by date:

Previous
From: Yugo Nagata
Date:
Subject: Re: Documentation fix on pgbench \aset command
Next
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: RE: Slot's restart_lsn may point to removed WAL segment after hard restart unexpectedly