Skip to content

Commit 733e49e

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 64f5962 commit 733e49e

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
@@ -2321,18 +2321,22 @@ BeginCopyFrom(Relation rel,
23212321
{
23222322
/* attribute is NOT to be copied from input */
23232323
/* use default value if one exists */
2324-
Node *defexpr = build_column_default(cstate->rel, attnum);
2324+
Expr *defexpr = (Expr *) build_column_default(cstate->rel,
2325+
attnum);
23252326

23262327
if (defexpr != NULL)
23272328
{
2328-
/* Initialize expressions in copycontext. */
2329-
defexprs[num_defaults] = ExecInitExpr(
2330-
expression_planner((Expr *) defexpr), NULL);
2329+
/* Run the expression through planner */
2330+
defexpr = expression_planner(defexpr);
2331+
2332+
/* Initialize executable expression in copycontext */
2333+
defexprs[num_defaults] = ExecInitExpr(defexpr, NULL);
23312334
defmap[num_defaults] = attnum - 1;
23322335
num_defaults++;
23332336

2337+
/* Check to see if we have any volatile expressions */
23342338
if (!volatile_defexprs)
2335-
volatile_defexprs = contain_volatile_functions(defexpr);
2339+
volatile_defexprs = contain_volatile_functions((Node *) defexpr);
23362340
}
23372341
}
23382342
}

0 commit comments

Comments
 (0)