3
3
* planmain.c
4
4
* Routines to plan a single query
5
5
*
6
+ * What's in a name, anyway? The top-level entry point of the planner/
7
+ * optimizer is over in planner.c, not here as you might think from the
8
+ * file name. But this is the main code for planning a basic join operation,
9
+ * shorn of features like subselects, inheritance, aggregates, grouping,
10
+ * and so on. (Those are the things planner.c deals with.)
11
+ *
6
12
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
7
13
* Portions Copyright (c) 1994, Regents of the University of California
8
14
*
9
15
*
10
16
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.52 2000/02/15 20:49:18 tgl Exp $
17
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.53 2000/03/21 05:11:58 tgl Exp $
12
18
*
13
19
*-------------------------------------------------------------------------
14
20
*/
15
- #include <sys/types.h>
16
-
17
21
#include "postgres.h"
18
22
23
+ #include <sys/types.h>
19
24
20
25
#include "optimizer/clauses.h"
21
26
#include "optimizer/cost.h"
22
27
#include "optimizer/pathnode.h"
23
28
#include "optimizer/paths.h"
24
29
#include "optimizer/planmain.h"
25
- #include "optimizer/prep.h"
26
- #include "optimizer/subselect.h"
27
30
#include "optimizer/tlist.h"
28
- #include "utils/lsyscache.h"
29
31
30
32
31
33
static Plan * subplanner (Query * root , List * flat_tlist , List * qual ,
@@ -34,19 +36,15 @@ static Plan *subplanner(Query *root, List *flat_tlist, List *qual,
34
36
35
37
/*--------------------
36
38
* query_planner
37
- * Routine to create a query plan. It does so by first creating a
38
- * subplan for the topmost level of attributes in the query. Then,
39
- * it modifies all target list and qualifications to consider the next
40
- * level of nesting and creates a plan for this modified query by
41
- * recursively calling itself. The two pieces are then merged together
42
- * by creating a result node that indicates which attributes should
43
- * be placed where and any relation level qualifications to be
44
- * satisfied.
39
+ * Generate a plan for a basic query, which may involve joins but
40
+ * not any fancier features.
45
41
*
46
- * tlist is the target list of the query (do NOT use root->targetList!)
42
+ * tlist is the target list the query should produce (NOT root->targetList!)
47
43
* qual is the qualification of the query (likewise!)
48
44
* tuple_fraction is the fraction of tuples we expect will be retrieved
49
45
*
46
+ * qual must already have been converted to implicit-AND form.
47
+ *
50
48
* Note: the Query node now also includes a query_pathkeys field, which
51
49
* is both an input and an output of query_planner(). The input value
52
50
* signals query_planner that the indicated sort order is wanted in the
@@ -83,46 +81,6 @@ query_planner(Query *root,
83
81
List * var_only_tlist ;
84
82
Plan * subplan ;
85
83
86
- /*
87
- * Note: union_planner should already have done constant folding
88
- * in both the tlist and qual, so we don't do it again here
89
- * (indeed, we may be getting a flattened var-only tlist anyway).
90
- *
91
- * Is there any value in re-folding the qual after canonicalize_qual?
92
- */
93
-
94
- /*
95
- * Canonicalize the qual, and convert it to implicit-AND format.
96
- */
97
- qual = canonicalize_qual ((Expr * ) qual , true);
98
- #ifdef OPTIMIZER_DEBUG
99
- printf ("After canonicalize_qual()\n" );
100
- pprint (qual );
101
- #endif
102
-
103
- /* Replace uplevel vars with Param nodes */
104
- if (PlannerQueryLevel > 1 )
105
- {
106
- tlist = (List * ) SS_replace_correlation_vars ((Node * ) tlist );
107
- qual = (List * ) SS_replace_correlation_vars ((Node * ) qual );
108
- }
109
-
110
- /* Expand SubLinks to SubPlans */
111
- if (root -> hasSubLinks )
112
- {
113
- tlist = (List * ) SS_process_sublinks ((Node * ) tlist );
114
- qual = (List * ) SS_process_sublinks ((Node * ) qual );
115
- if (root -> groupClause != NIL )
116
- {
117
- /*
118
- * Check for ungrouped variables passed to subplans.
119
- * Note we do NOT do this for subplans in WHERE; it's legal
120
- * there because WHERE is evaluated pre-GROUP.
121
- */
122
- check_subplans_for_ungrouped_vars ((Node * ) tlist , root , tlist );
123
- }
124
- }
125
-
126
84
/*
127
85
* If the query contains no relation references at all, it must be
128
86
* something like "SELECT 2+2;". Build a trivial "Result" plan.
@@ -192,16 +150,6 @@ query_planner(Query *root,
192
150
}
193
151
194
152
return subplan ;
195
-
196
- #ifdef NOT_USED
197
-
198
- /*
199
- * Destructively modify the query plan's targetlist to add fjoin lists
200
- * to flatten functions that return sets of base types
201
- */
202
- subplan -> targetlist = generate_fjoin (subplan -> targetlist );
203
- #endif
204
-
205
153
}
206
154
207
155
/*
0 commit comments