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

Commit 060b22a

Browse files
committed
Fix subtly-wrong volatility checking in BeginCopyFrom().
contain_volatile_functions() is best applied to the output of expression_planner(), not its input, so that insertion of function default arguments and constant-folding have been done. (See comments at CheckMutability, for instance.) It's perhaps unlikely that anyone will notice a difference in practice, but still we should do it properly. In passing, change variable type from Node* to Expr* to reduce the net number of casts needed. Noted while perusing uses of contain_volatile_functions().
1 parent 20803d7 commit 060b22a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/backend/commands/copy.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -2506,18 +2506,22 @@ BeginCopyFrom(Relation rel,
25062506
{
25072507
/* attribute is NOT to be copied from input */
25082508
/* use default value if one exists */
2509-
Node *defexpr = build_column_default(cstate->rel, attnum);
2509+
Expr *defexpr = (Expr *) build_column_default(cstate->rel,
2510+
attnum);
25102511

25112512
if (defexpr != NULL)
25122513
{
2513-
/* Initialize expressions in copycontext. */
2514-
defexprs[num_defaults] = ExecInitExpr(
2515-
expression_planner((Expr *) defexpr), NULL);
2514+
/* Run the expression through planner */
2515+
defexpr = expression_planner(defexpr);
2516+
2517+
/* Initialize executable expression in copycontext */
2518+
defexprs[num_defaults] = ExecInitExpr(defexpr, NULL);
25162519
defmap[num_defaults] = attnum - 1;
25172520
num_defaults++;
25182521

2522+
/* Check to see if we have any volatile expressions */
25192523
if (!volatile_defexprs)
2520-
volatile_defexprs = contain_volatile_functions(defexpr);
2524+
volatile_defexprs = contain_volatile_functions((Node *) defexpr);
25212525
}
25222526
}
25232527
}

0 commit comments

Comments
 (0)