mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +03:00
Don't include CaseTestExpr in JsonValueExpr.formatted_expr
A CaseTestExpr is currently being put into JsonValueExpr.formatted_expr as placeholder for the result of evaluating JsonValueExpr.raw_expr, which in turn is evaluated separately. Though, there's no need for this indirection if raw_expr itself can be embedded into formatted_expr and evaluated as part of evaluating the latter, especially as there is no special reason to evaluate it separately. So this commit makes it so. As a result, JsonValueExpr.raw_expr no longer needs to be evaluated in ExecInterpExpr(), eval_const_exprs_mutator() etc. and is now only used for displaying the original "unformatted" expression in ruleutils.c. Comments about and the code manipulating formatted_expr is updated to mention that it is now always set and is the expression that gives a JsonValueExpr its runtime value. While at it, this also removes the function makeCaseTestExpr(), because the code in makeJsonConstructorExpr() looks more readable without it IMO and isn't used by anyone else either. Finally, a note is added in the comment above CaseTestExpr's definition that JsonConstructorExpr is also using it. Backpatched to 16 from the development branch to keep the code in sync across branches. Reviewed-by: Álvaro Herrera <alvherre@alvh.no-ip.org> Discussion: https://postgr.es/m/CA+HiwqE4XTdfb1nW=Ojoy_tQSRhYt-q_kb6i5d4xcKyrLC1Nbg@mail.gmail.com
This commit is contained in:
@@ -2827,25 +2827,12 @@ eval_const_expressions_mutator(Node *node,
|
||||
case T_JsonValueExpr:
|
||||
{
|
||||
JsonValueExpr *jve = (JsonValueExpr *) node;
|
||||
Node *raw;
|
||||
Node *formatted;
|
||||
|
||||
raw = eval_const_expressions_mutator((Node *) jve->raw_expr,
|
||||
context);
|
||||
if (raw && IsA(raw, Const))
|
||||
{
|
||||
Node *formatted;
|
||||
Node *save_case_val = context->case_val;
|
||||
|
||||
context->case_val = raw;
|
||||
|
||||
formatted = eval_const_expressions_mutator((Node *) jve->formatted_expr,
|
||||
context);
|
||||
|
||||
context->case_val = save_case_val;
|
||||
|
||||
if (formatted && IsA(formatted, Const))
|
||||
return formatted;
|
||||
}
|
||||
formatted = eval_const_expressions_mutator((Node *) jve->formatted_expr,
|
||||
context);
|
||||
if (formatted && IsA(formatted, Const))
|
||||
return formatted;
|
||||
break;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user