summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planmain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-10-04 20:44:47 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-10-04 20:44:47 +0000
commit89db887b1edbeac7d7070e566606bbea4792f7f6 (patch)
tree85c24f810e78551ab384969c88ea748456a979c7 /src/backend/optimizer/plan/planmain.c
parent87dfa0d9ae803900ccdebb6b3c03eaaf23c90bf1 (diff)
Keep the planner from failing on "WHERE false AND something IN (SELECT ...)".
eval_const_expressions simplifies this to just "WHERE false", but we have already done pull_up_IN_clauses so the IN join will be done, or at least planned, anyway. The trouble case comes when the sub-SELECT is itself a join and we decide to implement the IN by unique-ifying the sub-SELECT outputs: with no remaining reference to the output Vars in WHERE, we won't have propagated the Vars up to the upper join point, leading to "variable not found in subplan target lists" error. Fix by adding an extra scan of in_info_list and forcing all Vars mentioned therein to be propagated up to the IN join point. Per bug report from Miroslav Sulc.
Diffstat (limited to 'src/backend/optimizer/plan/planmain.c')
-rw-r--r--src/backend/optimizer/plan/planmain.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c
index f8ff3a71508..772ee84e8d5 100644
--- a/src/backend/optimizer/plan/planmain.c
+++ b/src/backend/optimizer/plan/planmain.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.102 2007/07/07 20:46:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.103 2007/10/04 20:44:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -212,6 +212,13 @@ query_planner(PlannerInfo *root, List *tlist,
joinlist = deconstruct_jointree(root);
/*
+ * Vars mentioned in InClauseInfo items also have to be added to baserel
+ * targetlists. Nearly always, they'd have got there from the original
+ * WHERE qual, but in corner cases maybe not.
+ */
+ add_IN_vars_to_tlists(root);
+
+ /*
* Reconsider any postponed outer-join quals now that we have built up
* equivalence classes. (This could result in further additions or
* mergings of classes.)