1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Preserve exposed type of subquery outputs when substituting NULLs.

I thought I could get away with hardcoded int4 here, but the buildfarm
says differently.
This commit is contained in:
Tom Lane
2014-06-12 17:11:53 -04:00
parent d2783bee30
commit 9d4444a6fc

View File

@ -20,7 +20,6 @@
#include "access/sysattr.h" #include "access/sysattr.h"
#include "catalog/pg_class.h" #include "catalog/pg_class.h"
#include "catalog/pg_operator.h" #include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
#include "foreign/fdwapi.h" #include "foreign/fdwapi.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
@ -2117,6 +2116,7 @@ remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel)
foreach(lc, subquery->targetList) foreach(lc, subquery->targetList)
{ {
TargetEntry *tle = (TargetEntry *) lfirst(lc); TargetEntry *tle = (TargetEntry *) lfirst(lc);
Node *texpr = (Node *) tle->expr;
/* /*
* If it has a sortgroupref number, it's used in some sort/group * If it has a sortgroupref number, it's used in some sort/group
@ -2140,28 +2140,24 @@ remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel)
* If it contains a set-returning function, we can't remove it since * If it contains a set-returning function, we can't remove it since
* that could change the number of rows returned by the subquery. * that could change the number of rows returned by the subquery.
*/ */
if (expression_returns_set((Node *) tle->expr)) if (expression_returns_set(texpr))
continue; continue;
/* /*
* If it contains volatile functions, we daren't remove it for fear * If it contains volatile functions, we daren't remove it for fear
* that the user is expecting their side-effects to happen. * that the user is expecting their side-effects to happen.
*/ */
if (contain_volatile_functions((Node *) tle->expr)) if (contain_volatile_functions(texpr))
continue; continue;
/* /*
* OK, we don't need it. Replace the expression with a NULL constant. * OK, we don't need it. Replace the expression with a NULL constant.
* We can just make the constant be of INT4 type, since nothing's * Preserve the exposed type of the expression, in case something
* going to look at it anyway. * looks at the rowtype of the subquery's result.
*/ */
tle->expr = (Expr *) makeConst(INT4OID, tle->expr = (Expr *) makeNullConst(exprType(texpr),
-1, exprTypmod(texpr),
InvalidOid, exprCollation(texpr));
sizeof(int32),
(Datum) 0,
true, /* isnull */
true /* byval */ );
} }
} }