Skip to content

Commit 4b8b356

Browse files
committed
Avoid scribbling on input node tree in CREATE/ALTER DOMAIN.
This works fine in the "simple Query" code path; but if the statement is in the plan cache then it's corrupted for future re-execution. Apply copyObject() to protect the original tree from modification, as we've done elsewhere. This narrow fix is applied only to the back branches. In HEAD, the problem was fixed more generally by commit 7c337b6; but that changed ProcessUtility's API, so it's infeasible to back-patch. Per bug #17053 from Charles Samborski. Discussion: https://postgr.es/m/931771.1623893989@sss.pgh.pa.us Discussion: https://postgr.es/m/17053-3ca3f501bbc212b4@postgresql.org
1 parent 0d3b69a commit 4b8b356

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/backend/commands/typecmds.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -908,10 +908,12 @@ DefineDomain(CreateDomainStmt *stmt)
908908
pstate = make_parsestate(NULL);
909909

910910
/*
911-
* Cook the constr->raw_expr into an expression. Note:
912-
* name is strictly for error message
911+
* Cook the constr->raw_expr into an expression; copy it
912+
* in case the input is in plan cache. Note: name is used
913+
* only for error messages.
913914
*/
914-
defaultExpr = cookDefault(pstate, constr->raw_expr,
915+
defaultExpr = cookDefault(pstate,
916+
copyObject(constr->raw_expr),
915917
basetypeoid,
916918
basetypeMod,
917919
domainName);
@@ -2262,10 +2264,10 @@ AlterDomainDefault(List *names, Node *defaultRaw)
22622264
pstate = make_parsestate(NULL);
22632265

22642266
/*
2265-
* Cook the colDef->raw_expr into an expression. Note: Name is
2266-
* strictly for error message
2267+
* Cook the raw default into an expression; copy it in case the input
2268+
* is in plan cache. Note: name is used only for error messages.
22672269
*/
2268-
defaultExpr = cookDefault(pstate, defaultRaw,
2270+
defaultExpr = cookDefault(pstate, copyObject(defaultRaw),
22692271
typTup->typbasetype,
22702272
typTup->typtypmod,
22712273
NameStr(typTup->typname));
@@ -3136,7 +3138,12 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
31363138
pstate->p_pre_columnref_hook = replace_domain_constraint_value;
31373139
pstate->p_ref_hook_state = (void *) domVal;
31383140

3139-
expr = transformExpr(pstate, constr->raw_expr, EXPR_KIND_DOMAIN_CHECK);
3141+
/*
3142+
* Transform the expression; first we must copy the input, in case it's in
3143+
* plan cache.
3144+
*/
3145+
expr = transformExpr(pstate, copyObject(constr->raw_expr),
3146+
EXPR_KIND_DOMAIN_CHECK);
31403147

31413148
/*
31423149
* Make sure it yields a boolean result.

0 commit comments

Comments
 (0)