Skip to content

Commit abee4c2

Browse files
committed
Remove extraneous SeqScan node that make_noname was inserting
above a Sort or Materialize node. As far as I can tell, the only place that actually needed that was set_tlist_references, which was being lazy about checking to see if it had a noname node to fix or not...
1 parent 6defe49 commit abee4c2

File tree

2 files changed

+32
-40
lines changed

2 files changed

+32
-40
lines changed

src/backend/optimizer/plan/createplan.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.72 1999/08/16 23:07:20 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.73 1999/08/18 04:15:16 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -895,9 +895,7 @@ copy_costsize(Plan *dest, Plan *src)
895895

896896
/*
897897
* make_noname
898-
* Create plan nodes to sort or materialize relations into noname. The
899-
* result returned for a sort will look like (SEQSCAN(SORT(plan_node)))
900-
* or (SEQSCAN(MATERIAL(plan_node)))
898+
* Create plan node to sort or materialize relations into noname.
901899
*
902900
* 'tlist' is the target list of the scan to be sorted or materialized
903901
* 'pathkeys' is the list of pathkeys by which the result is to be sorted
@@ -911,8 +909,7 @@ make_noname(List *tlist,
911909
{
912910
List *noname_tlist;
913911
int numsortkeys;
914-
Plan *tmpplan;
915-
Noname *retval;
912+
Plan *retval;
916913

917914
/* Create a new target list for the noname, with sort keys set. */
918915
noname_tlist = new_unsorted_tlist(tlist);
@@ -921,27 +918,21 @@ make_noname(List *tlist,
921918
if (numsortkeys > 0)
922919
{
923920
/* need to sort */
924-
tmpplan = (Plan *) make_sort(noname_tlist,
925-
_NONAME_RELATION_ID_,
926-
plan_node,
927-
numsortkeys);
921+
retval = (Plan *) make_sort(noname_tlist,
922+
_NONAME_RELATION_ID_,
923+
plan_node,
924+
numsortkeys);
928925
}
929926
else
930927
{
931928
/* no sort */
932-
tmpplan = (Plan *) make_material(noname_tlist,
933-
_NONAME_RELATION_ID_,
934-
plan_node,
935-
0);
929+
retval = (Plan *) make_material(noname_tlist,
930+
_NONAME_RELATION_ID_,
931+
plan_node,
932+
0);
936933
}
937934

938-
/* Return a seqscan using the original tlist */
939-
retval = (Noname *) make_seqscan(tlist,
940-
NIL,
941-
_NONAME_RELATION_ID_,
942-
tmpplan);
943-
944-
return retval;
935+
return (Noname *) retval;
945936
}
946937

947938

src/backend/optimizer/plan/setrefs.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.54 1999/08/09 00:56:05 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.55 1999/08/18 04:15:16 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -82,10 +82,10 @@ set_tlist_references(Plan *plan)
8282

8383
if (IsA_Join(plan))
8484
set_join_tlist_references((Join *) plan);
85-
else if (IsA(plan, SeqScan) &&plan->lefttree &&
85+
else if (IsA(plan, SeqScan) && plan->lefttree &&
8686
IsA_Noname(plan->lefttree))
8787
set_nonamescan_tlist_references((SeqScan *) plan);
88-
else if (IsA(plan, Sort))
88+
else if (IsA_Noname(plan))
8989
set_noname_tlist_references((Noname *) plan);
9090
else if (IsA(plan, Result))
9191
set_result_tlist_references((Result *) plan);
@@ -112,12 +112,12 @@ set_tlist_references(Plan *plan)
112112
static void
113113
set_join_tlist_references(Join *join)
114114
{
115-
Plan *outer = ((Plan *) join)->lefttree;
116-
Plan *inner = ((Plan *) join)->righttree;
115+
Plan *outer = join->lefttree;
116+
Plan *inner = join->righttree;
117117
List *outer_tlist = ((outer == NULL) ? NIL : outer->targetlist);
118118
List *inner_tlist = ((inner == NULL) ? NIL : inner->targetlist);
119119
List *new_join_targetlist = NIL;
120-
List *qptlist = ((Plan *) join)->targetlist;
120+
List *qptlist = join->targetlist;
121121
List *entry;
122122

123123
foreach(entry, qptlist)
@@ -130,18 +130,16 @@ set_join_tlist_references(Join *join)
130130
new_join_targetlist = lappend(new_join_targetlist,
131131
makeTargetEntry(xtl->resdom, joinexpr));
132132
}
133+
join->targetlist = new_join_targetlist;
133134

134-
((Plan *) join)->targetlist = new_join_targetlist;
135-
if (outer != NULL)
136-
set_tlist_references(outer);
137-
if (inner != NULL)
138-
set_tlist_references(inner);
135+
set_tlist_references(outer);
136+
set_tlist_references(inner);
139137
}
140138

141139
/*
142140
* set_nonamescan_tlist_references
143141
* Modifies the target list of a node that scans a noname relation (i.e., a
144-
* sort or hash node) so that the varnos refer to the child noname.
142+
* sort or materialize node) so that the varnos refer to the child noname.
145143
*
146144
* 'nonamescan' is a seqscan node
147145
*
@@ -151,10 +149,13 @@ set_join_tlist_references(Join *join)
151149
static void
152150
set_nonamescan_tlist_references(SeqScan *nonamescan)
153151
{
154-
Noname *noname = (Noname *) ((Plan *) nonamescan)->lefttree;
152+
Noname *noname = (Noname *) nonamescan->plan.lefttree;
155153

156-
((Plan *) nonamescan)->targetlist = tlist_noname_references(noname->nonameid,
157-
((Plan *) nonamescan)->targetlist);
154+
nonamescan->plan.targetlist = tlist_noname_references(noname->nonameid,
155+
nonamescan->plan.targetlist);
156+
/* since we know child is a Noname, skip recursion through
157+
* set_tlist_references() and just get the job done
158+
*/
158159
set_noname_tlist_references(noname);
159160
}
160161

@@ -164,21 +165,21 @@ set_nonamescan_tlist_references(SeqScan *nonamescan)
164165
* modified version of the target list of the node from which noname node
165166
* receives its tuples.
166167
*
167-
* 'noname' is a noname (e.g., sort, hash) plan node
168+
* 'noname' is a noname (e.g., sort, materialize) plan node
168169
*
169170
* Returns nothing of interest, but modifies internal fields of nodes.
170171
*
171172
*/
172173
static void
173174
set_noname_tlist_references(Noname *noname)
174175
{
175-
Plan *source = ((Plan *) noname)->lefttree;
176+
Plan *source = noname->plan.lefttree;
176177

177178
if (source != NULL)
178179
{
179180
set_tlist_references(source);
180-
((Plan *) noname)->targetlist = copy_vars(((Plan *) noname)->targetlist,
181-
(source)->targetlist);
181+
noname->plan.targetlist = copy_vars(noname->plan.targetlist,
182+
source->targetlist);
182183
}
183184
else
184185
elog(ERROR, "calling set_noname_tlist_references with empty lefttree");

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