@@ -4414,8 +4414,6 @@ ExecInitJsonExpr(JsonExpr *jsexpr, ExprState *state,
44144414 ErrorSaveContext * escontext =
44154415 jsexpr -> on_error -> btype != JSON_BEHAVIOR_ERROR ?
44164416 & jsestate -> escontext : NULL ;
4417- bool returning_domain =
4418- get_typtype (jsexpr -> returning -> typid ) == TYPTYPE_DOMAIN ;
44194417
44204418 jsestate -> jsexpr = jsexpr ;
44214419
@@ -4558,27 +4556,20 @@ ExecInitJsonExpr(JsonExpr *jsexpr, ExprState *state,
45584556 ExprEvalPushStep (state , scratch );
45594557 }
45604558
4559+ jsestate -> jump_empty = jsestate -> jump_error = -1 ;
4560+
45614561 /*
45624562 * Step to check jsestate->error and return the ON ERROR expression if
45634563 * there is one. This handles both the errors that occur during jsonpath
45644564 * evaluation in EEOP_JSONEXPR_PATH and subsequent coercion evaluation.
4565- *
4566- * Speed up common cases by avoiding extra steps for a NULL-valued ON
4567- * ERROR expression unless RETURNING a domain type, where constraints must
4568- * be checked. ExecEvalJsonExprPath() already returns NULL on error,
4569- * making additional steps unnecessary in typical scenarios. Note that the
4570- * default ON ERROR behavior for JSON_VALUE() and JSON_QUERY() is to
4571- * return NULL.
45724565 */
4573- jsestate -> jump_error = state -> steps_len ;
45744566 if (jsexpr -> on_error &&
4575- jsexpr -> on_error -> btype != JSON_BEHAVIOR_ERROR &&
4576- (!(IsA (jsexpr -> on_error -> expr , Const ) &&
4577- ((Const * ) jsexpr -> on_error -> expr )-> constisnull ) ||
4578- returning_domain ))
4567+ jsexpr -> on_error -> btype != JSON_BEHAVIOR_ERROR )
45794568 {
45804569 ErrorSaveContext * saved_escontext ;
45814570
4571+ jsestate -> jump_error = state -> steps_len ;
4572+
45824573 /* JUMP to end if false, that is, skip the ON ERROR expression. */
45834574 jumps_to_end = lappend_int (jumps_to_end , state -> steps_len );
45844575 scratch -> opcode = EEOP_JUMP_IF_NOT_TRUE ;
@@ -4628,19 +4619,14 @@ ExecInitJsonExpr(JsonExpr *jsexpr, ExprState *state,
46284619 /*
46294620 * Step to check jsestate->empty and return the ON EMPTY expression if
46304621 * there is one.
4631- *
4632- * See the comment above for details on the optimization for NULL-valued
4633- * expressions.
46344622 */
4635- jsestate -> jump_empty = state -> steps_len ;
46364623 if (jsexpr -> on_empty != NULL &&
4637- jsexpr -> on_empty -> btype != JSON_BEHAVIOR_ERROR &&
4638- (!(IsA (jsexpr -> on_empty -> expr , Const ) &&
4639- ((Const * ) jsexpr -> on_empty -> expr )-> constisnull ) ||
4640- returning_domain ))
4624+ jsexpr -> on_empty -> btype != JSON_BEHAVIOR_ERROR )
46414625 {
46424626 ErrorSaveContext * saved_escontext ;
46434627
4628+ jsestate -> jump_empty = state -> steps_len ;
4629+
46444630 /* JUMP to end if false, that is, skip the ON EMPTY expression. */
46454631 jumps_to_end = lappend_int (jumps_to_end , state -> steps_len );
46464632 scratch -> opcode = EEOP_JUMP_IF_NOT_TRUE ;
0 commit comments