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

Commit 3c24b08

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 e348043 commit 3c24b08

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/backend/commands/copy.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,18 +2500,22 @@ BeginCopyFrom(Relation rel,
25002500
{
25012501
/* attribute is NOT to be copied from input */
25022502
/* use default value if one exists */
2503-
Node *defexpr = build_column_default(cstate->rel, attnum);
2503+
Expr *defexpr = (Expr *) build_column_default(cstate->rel,
2504+
attnum);
25042505

25052506
if (defexpr != NULL)
25062507
{
2507-
/* Initialize expressions in copycontext. */
2508-
defexprs[num_defaults] = ExecInitExpr(
2509-
expression_planner((Expr *) defexpr), NULL);
2508+
/* Run the expression through planner */
2509+
defexpr = expression_planner(defexpr);
2510+
2511+
/* Initialize executable expression in copycontext */
2512+
defexprs[num_defaults] = ExecInitExpr(defexpr, NULL);
25102513
defmap[num_defaults] = attnum - 1;
25112514
num_defaults++;
25122515

2516+
/* Check to see if we have any volatile expressions */
25132517
if (!volatile_defexprs)
2514-
volatile_defexprs = contain_volatile_functions(defexpr);
2518+
volatile_defexprs = contain_volatile_functions((Node *) defexpr);
25152519
}
25162520
}
25172521
}

0 commit comments

Comments
 (0)