aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-11-03 17:34:03 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-11-03 17:34:03 +0000
commitabf293e155e6625845169d42c33d77d381e40d6a (patch)
tree364a6c332e25a193059fc95711ef5e7f9a88aaf2
parent902377c465031947d747bb2e3912b22a92329b7f (diff)
downloadpostgresql-abf293e155e6625845169d42c33d77d381e40d6a.tar.gz
postgresql-abf293e155e6625845169d42c33d77d381e40d6a.zip
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.
-rw-r--r--src/backend/optimizer/plan/setrefs.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c
index 2ca616e118b..9f078924c25 100644
--- a/src/backend/optimizer/plan/setrefs.c
+++ b/src/backend/optimizer/plan/setrefs.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.115 2005/10/15 02:49:20 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.116 2005/11/03 17:34:03 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -359,6 +359,8 @@ set_subqueryscan_references(SubqueryScan *plan, List *rtable)
*/
int rtoffset = list_length(rtable);
List *sub_rtable;
+ ListCell *lp,
+ *lc;
sub_rtable = copyObject(rte->subquery->rtable);
range_table_walker(sub_rtable,
@@ -378,6 +380,19 @@ set_subqueryscan_references(SubqueryScan *plan, List *rtable)
result->initPlan = list_concat(plan->scan.plan.initPlan,
result->initPlan);
+
+ /*
+ * we also have to transfer the SubqueryScan's result-column names
+ * into the subplan, else columns sent to client will be improperly
+ * labeled if this is the topmost plan level.
+ */
+ forboth(lp, plan->scan.plan.targetlist, lc, result->targetlist)
+ {
+ TargetEntry *ptle = (TargetEntry *) lfirst(lp);
+ TargetEntry *ctle = (TargetEntry *) lfirst(lc);
+
+ ctle->resname = ptle->resname;
+ }
}
else
{