|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.39 1999/08/26 05:07:41 tgl Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.40 1999/10/07 04:23:06 tgl Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -77,37 +77,43 @@ add_vars_to_targetlist(Query *root, List *vars)
|
77 | 77 | }
|
78 | 78 |
|
79 | 79 | /*
|
80 |
| - * add_missing_vars_to_tlist |
81 |
| - * If we have range variable(s) in the FROM clause that does not appear |
82 |
| - * in the target list nor qualifications, we add it to the base relation |
83 |
| - * list. For instance, "select f.x from foo f, foo f2" is a join of f and |
84 |
| - * f2. Note that if we have "select foo.x from foo f", it also gets turned |
85 |
| - * into a join. |
| 80 | + * add_missing_rels_to_query |
| 81 | + * |
| 82 | + * If we have a range variable in the FROM clause that does not appear |
| 83 | + * in the target list nor qualifications, we must add it to the base |
| 84 | + * relation list so that it will be joined. For instance, "select f.x |
| 85 | + * from foo f, foo f2" is a join of f and f2. Note that if we have |
| 86 | + * "select foo.x from foo f", it also gets turned into a join (between |
| 87 | + * foo as foo and foo as f). |
| 88 | + * |
| 89 | + * To avoid putting useless entries into the per-relation targetlists, |
| 90 | + * this should only be called after all the variables in the targetlist |
| 91 | + * and quals have been processed by the routines above. |
86 | 92 | */
|
87 | 93 | void
|
88 |
| -add_missing_vars_to_tlist(Query *root, List *tlist) |
| 94 | +add_missing_rels_to_query(Query *root) |
89 | 95 | {
|
90 | 96 | int varno = 1;
|
91 | 97 | List *l;
|
92 | 98 |
|
93 | 99 | foreach(l, root->rtable)
|
94 | 100 | {
|
95 | 101 | RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
|
96 |
| - Relids relids; |
97 | 102 |
|
98 |
| - relids = lconsi(varno, NIL); |
99 |
| - if (rte->inFromCl && !rel_member(relids, root->base_rel_list)) |
| 103 | + if (rte->inJoinSet) |
100 | 104 | {
|
101 |
| - RelOptInfo *rel; |
102 |
| - Var *var; |
103 |
| - |
104 |
| - /* add it to base_rel_list */ |
105 |
| - rel = get_base_rel(root, varno); |
106 |
| - /* give it a dummy tlist entry for its OID */ |
107 |
| - var = makeVar(varno, ObjectIdAttributeNumber, OIDOID, -1, 0); |
108 |
| - add_var_to_tlist(rel, var); |
| 105 | + RelOptInfo *rel = get_base_rel(root, varno); |
| 106 | + |
| 107 | + /* If the rel isn't otherwise referenced, give it a dummy |
| 108 | + * targetlist consisting of its own OID. |
| 109 | + */ |
| 110 | + if (rel->targetlist == NIL) |
| 111 | + { |
| 112 | + Var *var = makeVar(varno, ObjectIdAttributeNumber, |
| 113 | + OIDOID, -1, 0); |
| 114 | + add_var_to_tlist(rel, var); |
| 115 | + } |
109 | 116 | }
|
110 |
| - pfree(relids); |
111 | 117 | varno++;
|
112 | 118 | }
|
113 | 119 | }
|
|
0 commit comments