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

Commit e9b6482

Browse files
committed
Improve comments for execExpr.c's isAssignmentIndirectionExpr().
I got confused about why this function doesn't need to recursively search the expression tree for a CaseTestExpr node. After figuring that out, add a comment to save the next person some time.
1 parent 837255c commit e9b6482

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/backend/executor/execExpr.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -2443,14 +2443,14 @@ ExecInitArrayRef(ExprEvalStep *scratch, ArrayRef *aref, PlanState *parent,
24432443
* refassgnexpr is itself a FieldStore or ArrayRef that needs to
24442444
* obtain and modify the previous value of the array element or slice
24452445
* being replaced. If so, we have to extract that value from the
2446-
* array and pass it down via the CaseTextExpr mechanism. It's safe
2446+
* array and pass it down via the CaseTestExpr mechanism. It's safe
24472447
* to reuse the CASE mechanism because there cannot be a CASE between
24482448
* here and where the value would be needed, and an array assignment
24492449
* can't be within a CASE either. (So saving and restoring
24502450
* innermost_caseval is just paranoia, but let's do it anyway.)
24512451
*
24522452
* Since fetching the old element might be a nontrivial expense, do it
2453-
* only if the argument appears to actually need it.
2453+
* only if the argument actually needs it.
24542454
*/
24552455
if (isAssignmentIndirectionExpr(aref->refassgnexpr))
24562456
{
@@ -2506,10 +2506,16 @@ ExecInitArrayRef(ExprEvalStep *scratch, ArrayRef *aref, PlanState *parent,
25062506

25072507
/*
25082508
* Helper for preparing ArrayRef expressions for evaluation: is expr a nested
2509-
* FieldStore or ArrayRef that might need the old element value passed down?
2509+
* FieldStore or ArrayRef that needs the old element value passed down?
25102510
*
25112511
* (We could use this in FieldStore too, but in that case passing the old
25122512
* value is so cheap there's no need.)
2513+
*
2514+
* Note: it might seem that this needs to recurse, but it does not; the
2515+
* CaseTestExpr, if any, will be directly the arg or refexpr of the top-level
2516+
* node. Nested-assignment situations give rise to expression trees in which
2517+
* each level of assignment has its own CaseTestExpr, and the recursive
2518+
* structure appears within the newvals or refassgnexpr field.
25132519
*/
25142520
static bool
25152521
isAssignmentIndirectionExpr(Expr *expr)

0 commit comments

Comments
 (0)