aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-03-06 22:45:35 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-03-06 22:45:35 +0000
commit14686de2b5aa11532f7629af6ec42ea35e50455b (patch)
treed123e78b036c0d8e1c1a77da922602ff84eea560 /src
parent45c84659eea6fb54e791e28a1a816917abe0b3de (diff)
downloadpostgresql-14686de2b5aa11532f7629af6ec42ea35e50455b.tar.gz
postgresql-14686de2b5aa11532f7629af6ec42ea35e50455b.zip
Fix oversight in original coding of inline_function(): since
check_sql_fn_retval allows binary-compatibility cases, the expression extracted from an inline-able SQL function might have a type that is only binary-compatible with the declared function result type. To avoid possibly changing the semantics of the expression, we should insert a RelabelType node in such cases. This has only been shown to have bad consequences in recent 8.1 and up releases, but I suspect there may be failure cases in the older branches too, so patch it all the way back. Per bug #3116 from Greg Mullane. Along the way, fix an omission in eval_const_expressions_mutator: it failed to copy the relabelformat field when processing a RelabelType. No known observable failures from this, but it definitely isn't intended behavior.
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/util/clauses.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index 66b6df85dff..7e49287fd56 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.186.4.5 2007/02/02 00:03:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.186.4.6 2007/03/06 22:45:35 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -1580,6 +1580,7 @@ eval_const_expressions_mutator(Node *node,
newrelabel->arg = (Expr *) arg;
newrelabel->resulttype = relabel->resulttype;
newrelabel->resulttypmod = relabel->resulttypmod;
+ newrelabel->relabelformat = relabel->relabelformat;
return (Node *) newrelabel;
}
}
@@ -2260,8 +2261,9 @@ inline_function(Oid funcid, Oid result_type, List *args,
* no rewriting was needed; that's probably not important, but let's be
* careful.
*/
- (void) check_sql_fn_retval(result_type, get_typtype(result_type),
- querytree_list, NULL);
+ if (check_sql_fn_retval(result_type, get_typtype(result_type),
+ querytree_list, NULL))
+ goto fail; /* reject whole-tuple-result cases */
/*
* Additional validity checks on the expression. It mustn't return a
@@ -2347,6 +2349,21 @@ inline_function(Oid funcid, Oid result_type, List *args,
MemoryContextDelete(mycxt);
/*
+ * Since check_sql_fn_retval allows binary-compatibility cases, the
+ * expression we now have might return some type that's only binary
+ * compatible with the original expression result type. To avoid
+ * confusing matters, insert a RelabelType in such cases.
+ */
+ if (exprType(newexpr) != funcform->prorettype)
+ {
+ Assert(IsBinaryCoercible(exprType(newexpr), funcform->prorettype));
+ newexpr = (Node *) makeRelabelType((Expr *) newexpr,
+ funcform->prorettype,
+ -1,
+ COERCE_IMPLICIT_CAST);
+ }
+
+ /*
* Recursively try to simplify the modified expression. Here we must
* add the current function to the context list of active functions.
*/