mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
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
This commit is contained in:
@@ -1596,15 +1596,19 @@ typedef struct JsonReturning
|
||||
* JsonValueExpr -
|
||||
* representation of JSON value expression (expr [FORMAT JsonFormat])
|
||||
*
|
||||
* The actual value is obtained by evaluating formatted_expr. raw_expr is
|
||||
* only there for displaying the original user-written expression and is not
|
||||
* evaluated by ExecInterpExpr() and eval_const_exprs_mutator().
|
||||
* raw_expr is the user-specified value, while formatted_expr is the value
|
||||
* obtained by coercing raw_expr to the type required by either the FORMAT
|
||||
* clause or an enclosing node's RETURNING clause.
|
||||
*
|
||||
* When deparsing a JsonValueExpr, get_rule_expr() prints raw_expr. However,
|
||||
* during the evaluation of a JsonValueExpr, the value of formatted_expr
|
||||
* takes precedence over that of raw_expr.
|
||||
*/
|
||||
typedef struct JsonValueExpr
|
||||
{
|
||||
NodeTag type;
|
||||
Expr *raw_expr; /* raw expression */
|
||||
Expr *formatted_expr; /* formatted expression */
|
||||
Expr *raw_expr; /* user-specified expression */
|
||||
Expr *formatted_expr; /* coerced formatted expression */
|
||||
JsonFormat *format; /* FORMAT clause, if specified */
|
||||
} JsonValueExpr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user