88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.84 2000/06/18 22:44:09 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.85 2000/06/20 04: 22:21 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -94,7 +94,8 @@ planner(Query *parse)
9494 * Basically, this routine does the stuff that should only be done once
9595 * per Query object. It then calls union_planner, which may be called
9696 * recursively on the same Query node in order to handle UNIONs and/or
97- * inheritance. subquery_planner is called recursively from subselect.c.
97+ * inheritance. subquery_planner is called recursively from subselect.c
98+ * to handle sub-Query nodes found within the query's expressions.
9899 *
99100 * prepunion.c uses an unholy combination of calling union_planner when
100101 * recursing on the primary Query node, or subquery_planner when recursing
@@ -107,10 +108,6 @@ planner(Query *parse)
107108Plan *
108109subquery_planner (Query * parse ,double tuple_fraction )
109110{
110- List * l ;
111- List * rangetable = parse -> rtable ;
112- RangeTblEntry * rangeTblEntry ;
113-
114111/*
115112 * A HAVING clause without aggregates is equivalent to a WHERE clause
116113 * (except it can only refer to grouped fields). If there are no aggs
@@ -142,18 +139,6 @@ subquery_planner(Query *parse, double tuple_fraction)
142139parse -> qual = eval_const_expressions (parse -> qual );
143140parse -> havingQual = eval_const_expressions (parse -> havingQual );
144141
145- /*
146- * If the query is going to look for subclasses, but no subclasses
147- * actually exist, then we can optimise away the union that would
148- * otherwise happen and thus save some time.
149- */
150- foreach (l ,rangetable )
151- {
152- rangeTblEntry = (RangeTblEntry * )lfirst (l );
153- if (rangeTblEntry -> inh && !has_subclass (rangeTblEntry -> relid ))
154- rangeTblEntry -> inh = FALSE;
155- }
156-
157142/*
158143 * Canonicalize the qual, and convert it to implicit-AND format.
159144 *
@@ -257,10 +242,11 @@ union_planner(Query *parse,
257242List * group_pathkeys ;
258243List * sort_pathkeys ;
259244Index rt_index ;
245+ List * inheritors ;
260246
261247if (parse -> unionClause )
262248{
263- result_plan = ( Plan * ) plan_union_queries (parse );
249+ result_plan = plan_union_queries (parse );
264250/* XXX do we need to do this? bjm 12/19/97 */
265251tlist = preprocess_targetlist (tlist ,
266252parse -> commandType ,
@@ -269,9 +255,8 @@ union_planner(Query *parse,
269255
270256/*
271257 * We leave current_pathkeys NIL indicating we do not know sort
272- * order. Actually, for a normal UNION we have done an explicit
273- * sort; ought to change interface to plan_union_queries to pass
274- * that info back!
258+ * order. This is correct for the appended-together subplan
259+ * results, even if the subplans themselves produced sorted results.
275260 */
276261
277262/*
@@ -283,7 +268,8 @@ union_planner(Query *parse,
283268sort_pathkeys = make_pathkeys_for_sortclauses (parse -> sortClause ,
284269tlist );
285270}
286- else if ((rt_index = first_inherit_rt_entry (rangetable ))!= -1 )
271+ else if (find_inheritable_rt_entry (rangetable ,
272+ & rt_index ,& inheritors ))
287273{
288274List * sub_tlist ;
289275
@@ -296,8 +282,8 @@ union_planner(Query *parse,
296282/*
297283 * Recursively plan the subqueries needed for inheritance
298284 */
299- result_plan = ( Plan * ) plan_inherit_queries (parse ,sub_tlist ,
300- rt_index );
285+ result_plan = plan_inherit_queries (parse ,sub_tlist ,
286+ rt_index , inheritors );
301287
302288/*
303289 * Fix up outer target list. NOTE: unlike the case for