diff options
author | Amit Langote <amitlan@postgresql.org> | 2024-10-20 12:21:12 +0900 |
---|---|---|
committer | Amit Langote <amitlan@postgresql.org> | 2024-10-20 12:21:12 +0900 |
commit | 7148cb3e3067a21f98031ff4d01be8895b5d164e (patch) | |
tree | 7a63fac5cc43b18190680a96ddddf0d6e700464b /src/backend/executor/execExpr.c | |
parent | 053b6daeb9c5ec26289479ab63601f0cd39f51a7 (diff) |
SQL/JSON: Fix some oversights in commit b6e1157e7
The decision in b6e1157e7 to ignore raw_expr when evaluating a
JsonValueExpr was incorrect. While its value is not ultimately
used (since formatted_expr's value is), failing to initialize it
can lead to problems, for instance, when the expression tree in
raw_expr contains Aggref nodes, which must be initialized to
ensure the parent Agg node works correctly.
Also, optimize eval_const_expressions_mutator()'s handling of
JsonValueExpr a bit. Currently, when formatted_expr cannot be folded
into a constant, we end up processing it twice -- once directly in
eval_const_expressions_mutator() and again recursively via
ece_generic_processing(). This recursive processing is required to
handle raw_expr. To avoid the redundant processing of formatted_expr,
we now process raw_expr directly in eval_const_expressions_mutator().
Finally, update the comment of JsonValueExpr to describe the roles of
raw_expr and formatted_expr more clearly.
Bug: #18657
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Diagnosed-by: Fabio R. Sluzala <fabio3rs@gmail.com>
Diagnosed-by: Tender Wang <tndrwang@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/18657-1b90ccce2b16bdb8@postgresql.org
Backpatch-through: 16
Diffstat (limited to 'src/backend/executor/execExpr.c')
-rw-r--r-- | src/backend/executor/execExpr.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/backend/executor/execExpr.c b/src/backend/executor/execExpr.c index a5395536a13..ab89ad9afbf 100644 --- a/src/backend/executor/execExpr.c +++ b/src/backend/executor/execExpr.c @@ -2317,6 +2317,8 @@ ExecInitExprRec(Expr *node, ExprState *state, { JsonValueExpr *jve = (JsonValueExpr *) node; + Assert(jve->raw_expr != NULL); + ExecInitExprRec(jve->raw_expr, state, resv, resnull); Assert(jve->formatted_expr != NULL); ExecInitExprRec(jve->formatted_expr, state, resv, resnull); break; |