Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit de2af6e

Browse files
committed
Improve comments for execExpr.c's handling of FieldStore subexpressions.
Given this code's general eagerness to use subexpressions' output variables as temporary workspace, it's not exactly clear that it is safe for FieldStore to tell a newval subexpression that it can write into the same variable that is being supplied as a potential input. Document the chain of assumptions needed for that to be safe.
1 parent e9b6482 commit de2af6e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/backend/executor/execExpr.c

+12
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,18 @@ ExecInitExprRec(Expr *node, PlanState *parent, ExprState *state,
11161116
* field assignment can't be within a CASE either. (So
11171117
* saving and restoring innermost_caseval is just
11181118
* paranoia, but let's do it anyway.)
1119+
*
1120+
* Another non-obvious point is that it's safe to use the
1121+
* field's values[]/nulls[] entries as both the caseval
1122+
* source and the result address for this subexpression.
1123+
* That's okay only because (1) both FieldStore and
1124+
* ArrayRef evaluate their arg or refexpr inputs first,
1125+
* and (2) any such CaseTestExpr is directly the arg or
1126+
* refexpr input. So any read of the caseval will occur
1127+
* before there's a chance to overwrite it. Also, if
1128+
* multiple entries in the newvals/fieldnums lists target
1129+
* the same field, they'll effectively be applied
1130+
* left-to-right which is what we want.
11191131
*/
11201132
save_innermost_caseval = state->innermost_caseval;
11211133
save_innermost_casenull = state->innermost_casenull;

0 commit comments

Comments
 (0)