|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.133 2007/08/31 01:44:05 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.134 2007/10/04 20:44:47 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -136,6 +136,40 @@ build_base_rel_tlists(PlannerInfo *root, List *final_tlist)
|
136 | 136 | }
|
137 | 137 | }
|
138 | 138 |
|
| 139 | +/* |
| 140 | + * add_IN_vars_to_tlists |
| 141 | + * Add targetlist entries for each var needed in InClauseInfo entries |
| 142 | + * to the appropriate base relations. |
| 143 | + * |
| 144 | + * Normally this is a waste of time because scanning of the WHERE clause |
| 145 | + * will have added them. But it is possible that eval_const_expressions() |
| 146 | + * simplified away all references to the vars after the InClauseInfos were |
| 147 | + * made. We need the IN's righthand-side vars to be available at the join |
| 148 | + * anyway, in case we try to unique-ify the subselect's outputs. (The only |
| 149 | + * known case that provokes this is "WHERE false AND foo IN (SELECT ...)". |
| 150 | + * We don't try to be very smart about such cases, just correct.) |
| 151 | + */ |
| 152 | +void |
| 153 | +add_IN_vars_to_tlists(PlannerInfo *root) |
| 154 | +{ |
| 155 | + ListCell *l; |
| 156 | + |
| 157 | + foreach(l, root->in_info_list) |
| 158 | + { |
| 159 | + InClauseInfo *ininfo = (InClauseInfo *) lfirst(l); |
| 160 | + List *in_vars; |
| 161 | + |
| 162 | + in_vars = pull_var_clause((Node *) ininfo->sub_targetlist, false); |
| 163 | + if (in_vars != NIL) |
| 164 | + { |
| 165 | + add_vars_to_targetlist(root, in_vars, |
| 166 | + bms_union(ininfo->lefthand, |
| 167 | + ininfo->righthand)); |
| 168 | + list_free(in_vars); |
| 169 | + } |
| 170 | + } |
| 171 | +} |
| 172 | + |
139 | 173 | /*
|
140 | 174 | * add_vars_to_targetlist
|
141 | 175 | * For each variable appearing in the list, add it to the owning
|
|
0 commit comments