Commit 060b22a9 authored by Tom Lane's avatar Tom Lane

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().
parent 20803d78
...@@ -2506,18 +2506,22 @@ BeginCopyFrom(Relation rel, ...@@ -2506,18 +2506,22 @@ BeginCopyFrom(Relation rel,
{ {
/* attribute is NOT to be copied from input */ /* attribute is NOT to be copied from input */
/* use default value if one exists */ /* use default value if one exists */
Node *defexpr = build_column_default(cstate->rel, attnum); Expr *defexpr = (Expr *) build_column_default(cstate->rel,
attnum);
if (defexpr != NULL) if (defexpr != NULL)
{ {
/* Initialize expressions in copycontext. */ /* Run the expression through planner */
defexprs[num_defaults] = ExecInitExpr( defexpr = expression_planner(defexpr);
expression_planner((Expr *) defexpr), NULL);
/* Initialize executable expression in copycontext */
defexprs[num_defaults] = ExecInitExpr(defexpr, NULL);
defmap[num_defaults] = attnum - 1; defmap[num_defaults] = attnum - 1;
num_defaults++; num_defaults++;
/* Check to see if we have any volatile expressions */
if (!volatile_defexprs) if (!volatile_defexprs)
volatile_defexprs = contain_volatile_functions(defexpr); volatile_defexprs = contain_volatile_functions((Node *) defexpr);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment