From aaca8c465a7273700358c1ad6debc2a44a35d937 Mon Sep 17 00:00:00 2001 From: jian he Date: Fri, 11 Jul 2025 12:00:10 +0800 Subject: [PATCH v12 1/1] minor refactor based on v12_0001_to_0006 --- src/backend/parser/parse_node.c | 27 ++------------------------- src/backend/utils/adt/jsonbsubs.c | 25 +++++++------------------ 2 files changed, 9 insertions(+), 43 deletions(-) diff --git a/src/backend/parser/parse_node.c b/src/backend/parser/parse_node.c index b3e476eb181..5c28d96fe60 100644 --- a/src/backend/parser/parse_node.c +++ b/src/backend/parser/parse_node.c @@ -321,31 +321,8 @@ transformContainerSubscripts(ParseState *pstate, sbsroutines->transform(sbsref, indirection, pstate, isSlice, isAssignment); - /* - * Error out, if datatype failed to consume any indirection elements. - */ - if (list_length(*indirection) == indirection_length) - { - Node *ind = linitial(*indirection); - - if (noError) - return NULL; - - if (IsA(ind, String)) - ereport(ERROR, - (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("type %s does not support dot notation", - format_type_be(containerType)), - parser_errposition(pstate, exprLocation(containerBase)))); - else if (IsA(ind, A_Indices)) - ereport(ERROR, - (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("type %s does not support array subscripting", - format_type_be(containerType)), - parser_errposition(pstate, exprLocation(containerBase)))); - else - elog(ERROR, "invalid indirection operation: %d", nodeTag(ind)); - } + /* datatype msut consume some indirection elements */ + Assert(indirection_length > list_length(*indirection)); /* * Verify we got a valid type (this defends, for example, against someone diff --git a/src/backend/utils/adt/jsonbsubs.c b/src/backend/utils/adt/jsonbsubs.c index c35d20933ea..4289ca41bd8 100644 --- a/src/backend/utils/adt/jsonbsubs.c +++ b/src/backend/utils/adt/jsonbsubs.c @@ -249,10 +249,6 @@ jsonb_subscript_make_jsonpath(ParseState *pstate, List **indirection, Subscripti int pathlen = 0; int warning_location = -1; - sbsref->refupperindexpr = NIL; - sbsref->reflowerindexpr = NIL; - sbsref->refjsonbpath = NULL; - jpres.expr = path; jpres.lax = true; @@ -325,16 +321,6 @@ jsonb_subscript_make_jsonpath(ParseState *pstate, List **indirection, Subscripti jpi->value.array.elems[0].to = NULL; } } - else - - /* - * Unsupported node type for creating jsonpath. Instead of - * throwing an ERROR, break here so that we create a jsonpath from - * as many indirection elements as we can and let - * transformIndirection() fallback to alternative logic to handle - * the remaining indirection elements. - */ - break; /* append path item */ path->next = jpi; @@ -376,11 +362,15 @@ jsonb_subscript_transform(SubscriptingRef *sbsref, List *upperIndexpr = NIL; ListCell *idx; + sbsref->refupperindexpr = NIL; + sbsref->reflowerindexpr = NIL; + sbsref->refjsonbpath = NULL; + /* Determine the result type of the subscripting operation; always jsonb */ sbsref->refrestype = JSONBOID; sbsref->reftypmod = -1; - if (jsonb_check_jsonpath_needed(*indirection)) + if (isSlice || jsonb_check_jsonpath_needed(*indirection)) { jsonb_subscript_make_jsonpath(pstate, indirection, sbsref); if (sbsref->refjsonbpath) @@ -388,9 +378,8 @@ jsonb_subscript_transform(SubscriptingRef *sbsref, } /* - * We would only reach here if json simplified accessor is not needed, or - * if jsonb_subscript_make_jsonpath() didn't consume any indirection - * element — either way, the first indirection element could not be + * We would only reach here if json simplified accessor is not needed, + * the first indirection element could not be * converted into a JsonPath component. This happens when it's a non-slice * A_Indices with a non-integer upper index. The code below falls back to * traditional jsonb subscripting for such cases. -- 2.34.1