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

From Chao Li
Subject Re: SQL:2023 JSON simplified accessor support
Date
Msg-id 290418A2-3A9B-4304-AAAD-4A40CFF1CB93@gmail.com
Whole thread Raw
In response to Re: SQL:2023 JSON simplified accessor support  (Alexandra Wang <alexandra.wang.oss@gmail.com>)
List pgsql-hackers


On Aug 26, 2025, at 11:52, Alexandra Wang <alexandra.wang.oss@gmail.com> wrote:

<v14-0002-Allow-Generic-Type-Subscripting-to-Accept-Dot-No.patch><v14-0003-Export-jsonPathFromParseResult.patch><v14-0001-Allow-transformation-of-only-a-sublist-of-subscr.patch><v14-0005-Implement-read-only-dot-notation-for-jsonb.patch><v14-0007-Implement-jsonb-wildcard-member-accessor.patch><v14-0006-Implement-Jsonb-subscripting-with-slicing.patch><v14-0004-Extract-coerce_jsonpath_subscript.patch>


A few other comments:

-static Node *
-transformIndirection(ParseState *pstate, A_Indirection *ind)
+Node *
+transformIndirection(ParseState *pstate, A_Indirection *ind,
+                                        bool *trailing_star_expansion)
 {
        Node       *last_srf = pstate->p_last_srf;
        Node       *result = transformExprRecurse(pstate, ind->arg);
@@ -454,12 +454,7 @@ transformIndirection(ParseState *pstate, A_Indirection *ind)
                if (IsA(n, A_Indices))
                        subscripts = lappend(subscripts, n);
                else if (IsA(n, A_Star))
-               {
-                       ereport(ERROR,
-                                       (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                                        errmsg("row expansion via \"*\" is not supported here"),
-                                        parser_errposition(pstate, location)));
-               }
+                       subscripts = lappend(subscripts, n);
                else
                {
                        Assert(IsA(n, String));

Now, the 3 clauses are quite similar, the if-elseif-else can be simplified as:

     If (!IsA(n, A_Indices) && !Is_A(n, A_Start))
          Assert(IsA(n, String));
     Subscripts = lappend(subscripts, n)

+static bool
+jsonb_check_jsonpath_needed(List *indirection)
+{
+       ListCell   *lc;
+
+       foreach(lc, indirection)
+       {
+               Node       *accessor = lfirst(lc);
+
+               if (IsA(accessor, String))
+                       return true;

Like I mentioned in my previous comment, if we convert String (dot notation) to Indices in rewritten phase, then jsonpath might be no longer needed, and the code logic is much simplified.


--- 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.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/




pgsql-hackers by date:

Previous
From: Andrey Borodin
Date:
Subject: Re: IPC/MultixactCreation on the Standby server
Next
From: Yugo Nagata
Date:
Subject: pgbench: extend variable usage in scripts