Skip to content

Commit abf293e

Browse files
committed
Fix the recently-added code that eliminates unnecessary SubqueryScan nodes
from a finished plan tree. We have to copy the output column names (resname fields) from the SubqueryScan down to its child plan node; else, if this is the topmost level of the plan, the wrong column names will be delivered to the client. Per bug #2017 reported by Jolly Chen.
1 parent 902377c commit abf293e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/backend/optimizer/plan/setrefs.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.115 2005/10/15 02:49:20 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.116 2005/11/03 17:34:03 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -359,6 +359,8 @@ set_subqueryscan_references(SubqueryScan *plan, List *rtable)
359359
*/
360360
int rtoffset = list_length(rtable);
361361
List *sub_rtable;
362+
ListCell *lp,
363+
*lc;
362364

363365
sub_rtable = copyObject(rte->subquery->rtable);
364366
range_table_walker(sub_rtable,
@@ -378,6 +380,19 @@ set_subqueryscan_references(SubqueryScan *plan, List *rtable)
378380

379381
result->initPlan = list_concat(plan->scan.plan.initPlan,
380382
result->initPlan);
383+
384+
/*
385+
* we also have to transfer the SubqueryScan's result-column names
386+
* into the subplan, else columns sent to client will be improperly
387+
* labeled if this is the topmost plan level.
388+
*/
389+
forboth(lp, plan->scan.plan.targetlist, lc, result->targetlist)
390+
{
391+
TargetEntry *ptle = (TargetEntry *) lfirst(lp);
392+
TargetEntry *ctle = (TargetEntry *) lfirst(lc);
393+
394+
ctle->resname = ptle->resname;
395+
}
381396
}
382397
else
383398
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy