1
0
mirror of https://github.com/postgres/postgres.git synced 2025-05-18 17:41:14 +03:00

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.
This commit is contained in:
Tom Lane 2007-03-06 22:45:41 +00:00
parent 88d482cf86
commit 9e4e0682bd

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.154.2.5 2007/02/02 00:04:02 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.154.2.6 2007/03/06 22:45:41 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
@ -31,6 +31,7 @@
#include "optimizer/var.h" #include "optimizer/var.h"
#include "parser/analyze.h" #include "parser/analyze.h"
#include "parser/parse_clause.h" #include "parser/parse_clause.h"
#include "parser/parse_coerce.h"
#include "parser/parse_expr.h" #include "parser/parse_expr.h"
#include "tcop/tcopprot.h" #include "tcop/tcopprot.h"
#include "utils/acl.h" #include "utils/acl.h"
@ -1414,6 +1415,7 @@ eval_const_expressions_mutator(Node *node, List *active_fns)
newrelabel->arg = (Expr *) arg; newrelabel->arg = (Expr *) arg;
newrelabel->resulttype = relabel->resulttype; newrelabel->resulttype = relabel->resulttype;
newrelabel->resulttypmod = relabel->resulttypmod; newrelabel->resulttypmod = relabel->resulttypmod;
newrelabel->relabelformat = relabel->relabelformat;
return (Node *) newrelabel; return (Node *) newrelabel;
} }
} }
@ -1979,6 +1981,21 @@ inline_function(Oid funcid, Oid result_type, List *args,
MemoryContextDelete(mycxt); 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 * Recursively try to simplify the modified expression. Here we must
* add the current function to the context list of active functions. * add the current function to the context list of active functions.