Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9d4444a

Browse files
committed
Preserve exposed type of subquery outputs when substituting NULLs.
I thought I could get away with hardcoded int4 here, but the buildfarm says differently.
1 parent d2783be commit 9d4444a

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/backend/optimizer/path/allpaths.c

+8-12
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "access/sysattr.h"
2121
#include "catalog/pg_class.h"
2222
#include "catalog/pg_operator.h"
23-
#include "catalog/pg_type.h"
2423
#include "foreign/fdwapi.h"
2524
#include "nodes/makefuncs.h"
2625
#include "nodes/nodeFuncs.h"
@@ -2117,6 +2116,7 @@ remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel)
21172116
foreach(lc, subquery->targetList)
21182117
{
21192118
TargetEntry *tle = (TargetEntry *) lfirst(lc);
2119+
Node *texpr = (Node *) tle->expr;
21202120

21212121
/*
21222122
* 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)
21402140
* If it contains a set-returning function, we can't remove it since
21412141
* that could change the number of rows returned by the subquery.
21422142
*/
2143-
if (expression_returns_set((Node *) tle->expr))
2143+
if (expression_returns_set(texpr))
21442144
continue;
21452145

21462146
/*
21472147
* If it contains volatile functions, we daren't remove it for fear
21482148
* that the user is expecting their side-effects to happen.
21492149
*/
2150-
if (contain_volatile_functions((Node *) tle->expr))
2150+
if (contain_volatile_functions(texpr))
21512151
continue;
21522152

21532153
/*
21542154
* OK, we don't need it. Replace the expression with a NULL constant.
2155-
* We can just make the constant be of INT4 type, since nothing's
2156-
* going to look at it anyway.
2155+
* Preserve the exposed type of the expression, in case something
2156+
* looks at the rowtype of the subquery's result.
21572157
*/
2158-
tle->expr = (Expr *) makeConst(INT4OID,
2159-
-1,
2160-
InvalidOid,
2161-
sizeof(int32),
2162-
(Datum) 0,
2163-
true, /* isnull */
2164-
true /* byval */ );
2158+
tle->expr = (Expr *) makeNullConst(exprType(texpr),
2159+
exprTypmod(texpr),
2160+
exprCollation(texpr));
21652161
}
21662162
}
21672163

0 commit comments

Comments
 (0)