Re: SQL/JSON json_table plan clause

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Nikita Malakhov <hukutoc(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: SQL/JSON json_table plan clause
Date: 2025-03-14 07:25:22
Message-ID: CA+HiwqErd3+tMB5yOerBeNJ5HzYWcByYjn=kJpEcSvdU9OADkg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Nikita,

I was looking at the patch you posted on Feb 3. Two high-level comments:

* The documentation additions are missing.

* It looks like the patch mixes refactoring changes with new
functionality, which makes it harder to follow what's existing vs.
new. Could you separate these changes so the new additions are easier
to review?

More specifically on the 2nd point:

-/*
- * Check if the type is "composite" for the purpose of checking whether to use
- * JSON_VALUE() or JSON_QUERY() for a given JsonTableColumn.
- */
-static bool
-isCompositeType(Oid typid)
-{
- char typtype = get_typtype(typid);
-
- return typid == JSONOID ||
- typid == JSONBOID ||
- typid == RECORDOID ||
- type_is_array(typid) ||
- typtype == TYPTYPE_COMPOSITE ||
- /* domain over one of the above? */
- (typtype == TYPTYPE_DOMAIN &&
- isCompositeType(getBaseType(typid)));
}
...

Diffs like this one make me wonder whether this code actually needs to
change for PLAN clause support -- but I suspect it does not.

+
+ /**/
+ bool cross;
+ bool outerJoin;
+ bool advanceNested;
+ bool advanceRight;
+ bool reset;

Incomplete comment.

@@ -4124,6 +4130,7 @@ JsonTableInitOpaque(TableFuncScanState *state, int natts)
* Evaluate JSON_TABLE() PASSING arguments to be passed to the jsonpath
* executor via JsonPathVariables.
*/
+
if (state->passingvalexprs)
@@ -4155,15 +4162,13 @@ JsonTableInitOpaque(TableFuncScanState *state,
int natts)
}

cxt->colplanstates = palloc(sizeof(JsonTablePlanState *) *
- list_length(tf->colvalexprs));
-
+ list_length(tf->colvalexprs));
/*
* Initialize plan for the root path and, recursively, also any child
* plans that compute the NESTED paths.
*/
cxt->rootplanstate = JsonTableInitPlan(cxt, rootplan, NULL, args,
- CurrentMemoryContext);
-
+ CurrentMemoryContext);
state->opaque = cxt;
}

@@ -4201,8 +4206,9 @@ JsonTableInitPlan(JsonTableExecContext *cxt,
JsonTablePlan *plan,
if (IsA(plan, JsonTablePathScan))
{
JsonTablePathScan *scan = (JsonTablePathScan *) plan;
- int i;
+ int i;

Unnecessary whitespace addition/removal.

/*
- * Transform JSON_TABLE column definition into a JsonFuncExpr
- * This turns:
+ * Transform JSON_TABLE column

Not sure why the comment was rewritten.

-JsonTableResetRowPattern(JsonTablePlanState *planstate, Datum item)
+JsonTableResetContextItem(JsonTablePlanState *planstate, Datum item)

I remember renaming ContextItem with RowPattern, but it seems this is
switching it back.

It makes it look like you're reverting to code from the old patch that
implemented the PLAN clause together with JSON_TABLE(), instead of
building on the committed code and adding just what's needed to
support PLAN clause in JsonTablePlan. Especially, the changes to
parse_jsontable.c and jsonpath_exec.c,

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhijie Hou (Fujitsu) 2025-03-14 07:25:54 RE: Adding a '--clean-publisher-objects' option to 'pg_createsubscriber' utility.
Previous Message David G. Johnston 2025-03-14 06:39:22 Re: Adding a '--clean-publisher-objects' option to 'pg_createsubscriber' utility.