Skip to content

Commit 102f31a

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 5b6b5e5 commit 102f31a

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
@@ -846,10 +846,12 @@ DefineDomain(CreateDomainStmt *stmt)
846846
pstate = make_parsestate(NULL);
847847

848848
/*
849-
* Cook the constr->raw_expr into an expression. Note:
850-
* name is strictly for error message
849+
* Cook the constr->raw_expr into an expression; copy it
850+
* in case the input is in plan cache. Note: name is used
851+
* only for error messages.
851852
*/
852-
defaultExpr = cookDefault(pstate, constr->raw_expr,
853+
defaultExpr = cookDefault(pstate,
854+
copyObject(constr->raw_expr),
853855
basetypeoid,
854856
basetypeMod,
855857
domainName,
@@ -2184,10 +2186,10 @@ AlterDomainDefault(List *names, Node *defaultRaw)
21842186
pstate = make_parsestate(NULL);
21852187

21862188
/*
2187-
* Cook the colDef->raw_expr into an expression. Note: Name is
2188-
* strictly for error message
2189+
* Cook the raw default into an expression; copy it in case the input
2190+
* is in plan cache. Note: name is used only for error messages.
21892191
*/
2190-
defaultExpr = cookDefault(pstate, defaultRaw,
2192+
defaultExpr = cookDefault(pstate, copyObject(defaultRaw),
21912193
typTup->typbasetype,
21922194
typTup->typtypmod,
21932195
NameStr(typTup->typname),
@@ -3069,7 +3071,12 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid,
30693071
pstate->p_pre_columnref_hook = replace_domain_constraint_value;
30703072
pstate->p_ref_hook_state = (void *) domVal;
30713073

3072-
expr = transformExpr(pstate, constr->raw_expr, EXPR_KIND_DOMAIN_CHECK);
3074+
/*
3075+
* Transform the expression; first we must copy the input, in case it's in
3076+
* plan cache.
3077+
*/
3078+
expr = transformExpr(pstate, copyObject(constr->raw_expr),
3079+
EXPR_KIND_DOMAIN_CHECK);
30733080

30743081
/*
30753082
* Make sure it yields a boolean result.

0 commit comments

Comments
 (0)