hi.
since InitJsonItemCoercions cannot return NULL.
per transformJsonFuncExpr, jsexpr->item_coercions not null imply
jsexpr->result_coercion not null.
so I did the attached refactoring.
now every ExecInitJsonExprCoercion function call followed with:
scratch->opcode = EEOP_JUMP;
scratch->d.jump.jumpdone = -1; /* set below */
jumps_to_coerce_finish = lappend_int(jumps_to_coerce_finish,
state->steps_len);
ExprEvalPushStep(state, scratch);
It looks more consistent.
we can also change
+ */
+ if (jexpr->result_coercion || jexpr->item_coercions)
+ {
+
to
+ if (jexpr->result_coercion)
since jexpr->item_coercions not null imply jexpr->result_coercion not null.
diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c
index 7239e4c1..9879a15b 100644
--- a/src/backend/executor/execExpr.c
+++ b/src/backend/executor/execExpr.c
@@ -4299,6 +4299,13 @@ ExecInitJsonExpr(JsonExpr *jexpr, ExprState *state,
jexpr->on_error->btype != JSON_BEHAVIOR_ERROR ?
&jsestate->escontext : NULL,
resv, resnull);
+
+ /* Jump to EEOP_JSONEXPR_COERCION_FINISH */
+ scratch->opcode = EEOP_JUMP;
+ scratch->d.jump.jumpdone = -1; /* set below */
+ jumps_to_coerce_finish = lappend_int(jumps_to_coerce_finish,
+ state->steps_len);
+ ExprEvalPushStep(state, scratch);
}
else
jsestate->jump_eval_result_coercion = -1;
@@ -4306,19 +4313,6 @@ ExecInitJsonExpr(JsonExpr *jexpr, ExprState *state,
/* Steps for coercing JsonItemType values returned by JsonPathValue(). */
if (jexpr->item_coercions)
{
- /*
- * Jump to COERCION_FINISH to skip over the following steps if
- * result_coercion is present.
- */
- if (jsestate->jump_eval_result_coercion >= 0)
- {
- scratch->opcode = EEOP_JUMP;
- scratch->d.jump.jumpdone = -1; /* set below */
- jumps_to_coerce_finish = lappend_int(jumps_to_coerce_finish,
- state->steps_len);
- ExprEvalPushStep(state, scratch);
- }
-
/*
* Here we create the steps for each JsonItemType type's coercion
* expression and also store a flag whether the expression is