Commit 9ab4d981 authored by Tom Lane's avatar Tom Lane

Remove planner's private fields from Query struct, and put them into

a new PlannerInfo struct, which is passed around instead of the bare
Query in all the planning code.  This commit is essentially just a
code-beautification exercise, but it does open the door to making
larger changes to the planner data structures without having to muck
with the widely-known Query struct.
parent 22dbd540
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.4 2005/04/20 22:19:58 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/indexam.sgml,v 2.5 2005/06/05 22:32:53 tgl Exp $
--> -->
<chapter id="indexam"> <chapter id="indexam">
...@@ -319,7 +319,7 @@ amrestrpos (IndexScanDesc scan); ...@@ -319,7 +319,7 @@ amrestrpos (IndexScanDesc scan);
<para> <para>
<programlisting> <programlisting>
void void
amcostestimate (Query *root, amcostestimate (PlannerInfo *root,
IndexOptInfo *index, IndexOptInfo *index,
List *indexQuals, List *indexQuals,
Cost *indexStartupCost, Cost *indexStartupCost,
...@@ -656,7 +656,7 @@ amcostestimate (Query *root, ...@@ -656,7 +656,7 @@ amcostestimate (Query *root,
<programlisting> <programlisting>
void void
amcostestimate (Query *root, amcostestimate (PlannerInfo *root,
IndexOptInfo *index, IndexOptInfo *index,
List *indexQuals, List *indexQuals,
Cost *indexStartupCost, Cost *indexStartupCost,
...@@ -672,7 +672,7 @@ amcostestimate (Query *root, ...@@ -672,7 +672,7 @@ amcostestimate (Query *root,
<term>root</term> <term>root</term>
<listitem> <listitem>
<para> <para>
The query being processed. The planner's information about the query being processed.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.304 2005/04/28 21:47:12 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.305 2005/06/05 22:32:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1615,18 +1615,6 @@ _copyQuery(Query *from) ...@@ -1615,18 +1615,6 @@ _copyQuery(Query *from)
COPY_NODE_FIELD(limitCount); COPY_NODE_FIELD(limitCount);
COPY_NODE_FIELD(setOperations); COPY_NODE_FIELD(setOperations);
COPY_NODE_FIELD(resultRelations); COPY_NODE_FIELD(resultRelations);
COPY_NODE_FIELD(in_info_list);
COPY_SCALAR_FIELD(hasJoinRTEs);
COPY_SCALAR_FIELD(hasHavingQual);
/*
* We do not copy the other planner internal fields: base_rel_list,
* other_rel_list, join_rel_list, equi_key_list, query_pathkeys. That
* would get us into copying RelOptInfo/Path trees, which we don't
* want to do. It is necessary to copy in_info_list, hasJoinRTEs,
* and hasHavingQual for the benefit of inheritance_planner(), which
* may try to copy a Query in which these are already set.
*/
return newnode; return newnode;
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.241 2005/04/28 21:47:12 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.242 2005/06/05 22:32:54 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -653,10 +653,6 @@ _equalQuery(Query *a, Query *b) ...@@ -653,10 +653,6 @@ _equalQuery(Query *a, Query *b)
COMPARE_NODE_FIELD(setOperations); COMPARE_NODE_FIELD(setOperations);
COMPARE_NODE_FIELD(resultRelations); COMPARE_NODE_FIELD(resultRelations);
/*
* We do not check the planner-internal fields. They might not be set
* yet, and in any case they should be derivable from the other fields.
*/
return true; return true;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.252 2005/05/09 15:09:19 ishii Exp $ * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.253 2005/06/05 22:32:54 tgl Exp $
* *
* NOTES * NOTES
* Every node type that can appear in stored rules' parsetrees *must* * Every node type that can appear in stored rules' parsetrees *must*
...@@ -1145,6 +1145,69 @@ _outHashPath(StringInfo str, HashPath *node) ...@@ -1145,6 +1145,69 @@ _outHashPath(StringInfo str, HashPath *node)
WRITE_NODE_FIELD(path_hashclauses); WRITE_NODE_FIELD(path_hashclauses);
} }
static void
_outPlannerInfo(StringInfo str, PlannerInfo *node)
{
WRITE_NODE_TYPE("PLANNERINFO");
WRITE_NODE_FIELD(parse);
WRITE_NODE_FIELD(base_rel_list);
WRITE_NODE_FIELD(other_rel_list);
WRITE_NODE_FIELD(join_rel_list);
WRITE_NODE_FIELD(equi_key_list);
WRITE_NODE_FIELD(in_info_list);
WRITE_NODE_FIELD(query_pathkeys);
WRITE_BOOL_FIELD(hasJoinRTEs);
WRITE_BOOL_FIELD(hasHavingQual);
}
static void
_outRelOptInfo(StringInfo str, RelOptInfo *node)
{
WRITE_NODE_TYPE("RELOPTINFO");
/* NB: this isn't a complete set of fields */
WRITE_ENUM_FIELD(reloptkind, RelOptKind);
WRITE_BITMAPSET_FIELD(relids);
WRITE_FLOAT_FIELD(rows, "%.0f");
WRITE_INT_FIELD(width);
WRITE_NODE_FIELD(reltargetlist);
WRITE_NODE_FIELD(pathlist);
WRITE_NODE_FIELD(cheapest_startup_path);
WRITE_NODE_FIELD(cheapest_total_path);
WRITE_NODE_FIELD(cheapest_unique_path);
WRITE_UINT_FIELD(relid);
WRITE_ENUM_FIELD(rtekind, RTEKind);
WRITE_UINT_FIELD(min_attr);
WRITE_UINT_FIELD(max_attr);
WRITE_NODE_FIELD(indexlist);
WRITE_UINT_FIELD(pages);
WRITE_FLOAT_FIELD(tuples, "%.0f");
WRITE_NODE_FIELD(subplan);
WRITE_NODE_FIELD(baserestrictinfo);
WRITE_BITMAPSET_FIELD(outerjoinset);
WRITE_NODE_FIELD(joininfo);
WRITE_BITMAPSET_FIELD(index_outer_relids);
WRITE_NODE_FIELD(index_inner_paths);
}
static void
_outIndexOptInfo(StringInfo str, IndexOptInfo *node)
{
WRITE_NODE_TYPE("INDEXOPTINFO");
/* NB: this isn't a complete set of fields */
WRITE_OID_FIELD(indexoid);
/* Do NOT print rel field, else infinite recursion */
WRITE_UINT_FIELD(pages);
WRITE_FLOAT_FIELD(tuples, "%.0f");
WRITE_INT_FIELD(ncolumns);
WRITE_NODE_FIELD(indexprs);
WRITE_NODE_FIELD(indpred);
WRITE_BOOL_FIELD(predOK);
WRITE_BOOL_FIELD(unique);
}
static void static void
_outPathKeyItem(StringInfo str, PathKeyItem *node) _outPathKeyItem(StringInfo str, PathKeyItem *node)
{ {
...@@ -1185,6 +1248,15 @@ _outJoinInfo(StringInfo str, JoinInfo *node) ...@@ -1185,6 +1248,15 @@ _outJoinInfo(StringInfo str, JoinInfo *node)
WRITE_NODE_FIELD(jinfo_restrictinfo); WRITE_NODE_FIELD(jinfo_restrictinfo);
} }
static void
_outInnerIndexscanInfo(StringInfo str, InnerIndexscanInfo *node)
{
WRITE_NODE_TYPE("INNERINDEXSCANINFO");
WRITE_BITMAPSET_FIELD(other_relids);
WRITE_BOOL_FIELD(isouterjoin);
WRITE_NODE_FIELD(best_innerpath);
}
static void static void
_outInClauseInfo(StringInfo str, InClauseInfo *node) _outInClauseInfo(StringInfo str, InClauseInfo *node)
{ {
...@@ -1395,8 +1467,6 @@ _outQuery(StringInfo str, Query *node) ...@@ -1395,8 +1467,6 @@ _outQuery(StringInfo str, Query *node)
WRITE_NODE_FIELD(limitCount); WRITE_NODE_FIELD(limitCount);
WRITE_NODE_FIELD(setOperations); WRITE_NODE_FIELD(setOperations);
WRITE_NODE_FIELD(resultRelations); WRITE_NODE_FIELD(resultRelations);
/* planner-internal fields are not written out */
} }
static void static void
...@@ -1905,6 +1975,15 @@ _outNode(StringInfo str, void *obj) ...@@ -1905,6 +1975,15 @@ _outNode(StringInfo str, void *obj)
case T_HashPath: case T_HashPath:
_outHashPath(str, obj); _outHashPath(str, obj);
break; break;
case T_PlannerInfo:
_outPlannerInfo(str, obj);
break;
case T_RelOptInfo:
_outRelOptInfo(str, obj);
break;
case T_IndexOptInfo:
_outIndexOptInfo(str, obj);
break;
case T_PathKeyItem: case T_PathKeyItem:
_outPathKeyItem(str, obj); _outPathKeyItem(str, obj);
break; break;
...@@ -1914,6 +1993,9 @@ _outNode(StringInfo str, void *obj) ...@@ -1914,6 +1993,9 @@ _outNode(StringInfo str, void *obj)
case T_JoinInfo: case T_JoinInfo:
_outJoinInfo(str, obj); _outJoinInfo(str, obj);
break; break;
case T_InnerIndexscanInfo:
_outInnerIndexscanInfo(str, obj);
break;
case T_InClauseInfo: case T_InClauseInfo:
_outInClauseInfo(str, obj); _outInClauseInfo(str, obj);
break; break;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.177 2005/04/28 21:47:13 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/readfuncs.c,v 1.178 2005/06/05 22:32:54 tgl Exp $
* *
* NOTES * NOTES
* Path and Plan nodes do not have any readfuncs support, because we * Path and Plan nodes do not have any readfuncs support, because we
...@@ -156,8 +156,6 @@ _readQuery(void) ...@@ -156,8 +156,6 @@ _readQuery(void)
READ_NODE_FIELD(setOperations); READ_NODE_FIELD(setOperations);
READ_NODE_FIELD(resultRelations); READ_NODE_FIELD(resultRelations);
/* planner-internal fields are left zero */
READ_DONE(); READ_DONE();
} }
......
...@@ -245,6 +245,8 @@ planner() ...@@ -245,6 +245,8 @@ planner()
Optimizer Data Structures Optimizer Data Structures
------------------------- -------------------------
PlannerInfo - global information for planning a particular Query
RelOptInfo - a relation or joined relations RelOptInfo - a relation or joined relations
RestrictInfo - WHERE clauses, like "x = 3" or "y = z" RestrictInfo - WHERE clauses, like "x = 3" or "y = z"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.73 2004/12/31 21:59:58 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.74 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "utils/memutils.h" #include "utils/memutils.h"
static bool desirable_join(Query *root, static bool desirable_join(PlannerInfo *root,
RelOptInfo *outer_rel, RelOptInfo *inner_rel); RelOptInfo *outer_rel, RelOptInfo *inner_rel);
...@@ -241,7 +241,7 @@ gimme_tree(Gene *tour, int num_gene, GeqoEvalData *evaldata) ...@@ -241,7 +241,7 @@ gimme_tree(Gene *tour, int num_gene, GeqoEvalData *evaldata)
* Heuristics for gimme_tree: do we want to join these two relations? * Heuristics for gimme_tree: do we want to join these two relations?
*/ */
static bool static bool
desirable_join(Query *root, desirable_join(PlannerInfo *root,
RelOptInfo *outer_rel, RelOptInfo *inner_rel) RelOptInfo *outer_rel, RelOptInfo *inner_rel)
{ {
ListCell *l; ListCell *l;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.48 2004/12/31 21:59:58 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_main.c,v 1.49 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -63,7 +63,7 @@ static int gimme_number_generations(int pool_size); ...@@ -63,7 +63,7 @@ static int gimme_number_generations(int pool_size);
*/ */
RelOptInfo * RelOptInfo *
geqo(Query *root, int number_of_rels, List *initial_rels) geqo(PlannerInfo *root, int number_of_rels, List *initial_rels)
{ {
GeqoEvalData evaldata; GeqoEvalData evaldata;
int generation; int generation;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.130 2005/06/04 19:19:41 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.131 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -38,17 +38,17 @@ bool enable_geqo = false; /* just in case GUC doesn't set it */ ...@@ -38,17 +38,17 @@ bool enable_geqo = false; /* just in case GUC doesn't set it */
int geqo_threshold; int geqo_threshold;
static void set_base_rel_pathlists(Query *root); static void set_base_rel_pathlists(PlannerInfo *root);
static void set_plain_rel_pathlist(Query *root, RelOptInfo *rel, static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
RangeTblEntry *rte); RangeTblEntry *rte);
static void set_inherited_rel_pathlist(Query *root, RelOptInfo *rel, static void set_inherited_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
Index rti, RangeTblEntry *rte, Index rti, RangeTblEntry *rte,
List *inheritlist); List *inheritlist);
static void set_subquery_pathlist(Query *root, RelOptInfo *rel, static void set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
Index rti, RangeTblEntry *rte); Index rti, RangeTblEntry *rte);
static void set_function_pathlist(Query *root, RelOptInfo *rel, static void set_function_pathlist(PlannerInfo *root, RelOptInfo *rel,
RangeTblEntry *rte); RangeTblEntry *rte);
static RelOptInfo *make_one_rel_by_joins(Query *root, int levels_needed, static RelOptInfo *make_one_rel_by_joins(PlannerInfo *root, int levels_needed,
List *initial_rels); List *initial_rels);
static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery, static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery,
bool *differentTypes); bool *differentTypes);
...@@ -70,7 +70,7 @@ static void recurse_push_qual(Node *setOp, Query *topquery, ...@@ -70,7 +70,7 @@ static void recurse_push_qual(Node *setOp, Query *topquery,
* single rel that represents the join of all base rels in the query. * single rel that represents the join of all base rels in the query.
*/ */
RelOptInfo * RelOptInfo *
make_one_rel(Query *root) make_one_rel(PlannerInfo *root)
{ {
RelOptInfo *rel; RelOptInfo *rel;
...@@ -82,9 +82,10 @@ make_one_rel(Query *root) ...@@ -82,9 +82,10 @@ make_one_rel(Query *root)
/* /*
* Generate access paths for the entire join tree. * Generate access paths for the entire join tree.
*/ */
Assert(root->jointree != NULL && IsA(root->jointree, FromExpr)); Assert(root->parse->jointree != NULL &&
IsA(root->parse->jointree, FromExpr));
rel = make_fromexpr_rel(root, root->jointree); rel = make_fromexpr_rel(root, root->parse->jointree);
/* /*
* The result should join all the query's base rels. * The result should join all the query's base rels.
...@@ -101,7 +102,7 @@ make_one_rel(Query *root) ...@@ -101,7 +102,7 @@ make_one_rel(Query *root)
* Each useful path is attached to its relation's 'pathlist' field. * Each useful path is attached to its relation's 'pathlist' field.
*/ */
static void static void
set_base_rel_pathlists(Query *root) set_base_rel_pathlists(PlannerInfo *root)
{ {
ListCell *l; ListCell *l;
...@@ -113,7 +114,7 @@ set_base_rel_pathlists(Query *root) ...@@ -113,7 +114,7 @@ set_base_rel_pathlists(Query *root)
List *inheritlist; List *inheritlist;
Assert(rti > 0); /* better be base rel */ Assert(rti > 0); /* better be base rel */
rte = rt_fetch(rti, root->rtable); rte = rt_fetch(rti, root->parse->rtable);
if (rel->rtekind == RTE_SUBQUERY) if (rel->rtekind == RTE_SUBQUERY)
{ {
...@@ -147,7 +148,7 @@ set_base_rel_pathlists(Query *root) ...@@ -147,7 +148,7 @@ set_base_rel_pathlists(Query *root)
* Build access paths for a plain relation (no subquery, no inheritance) * Build access paths for a plain relation (no subquery, no inheritance)
*/ */
static void static void
set_plain_rel_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte) set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
{ {
/* Mark rel with estimated output rows, width, etc */ /* Mark rel with estimated output rows, width, etc */
set_baserel_size_estimates(root, rel); set_baserel_size_estimates(root, rel);
...@@ -204,7 +205,7 @@ set_plain_rel_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte) ...@@ -204,7 +205,7 @@ set_plain_rel_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
* not the same size. * not the same size.
*/ */
static void static void
set_inherited_rel_pathlist(Query *root, RelOptInfo *rel, set_inherited_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
Index rti, RangeTblEntry *rte, Index rti, RangeTblEntry *rte,
List *inheritlist) List *inheritlist)
{ {
...@@ -217,7 +218,7 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel, ...@@ -217,7 +218,7 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
* XXX for now, can't handle inherited expansion of FOR UPDATE/SHARE; * XXX for now, can't handle inherited expansion of FOR UPDATE/SHARE;
* can we do better? * can we do better?
*/ */
if (list_member_int(root->rowMarks, parentRTindex)) if (list_member_int(root->parse->rowMarks, parentRTindex))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE is not supported for inheritance queries"))); errmsg("SELECT FOR UPDATE/SHARE is not supported for inheritance queries")));
...@@ -241,7 +242,7 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel, ...@@ -241,7 +242,7 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
ListCell *parentvars; ListCell *parentvars;
ListCell *childvars; ListCell *childvars;
childrte = rt_fetch(childRTindex, root->rtable); childrte = rt_fetch(childRTindex, root->parse->rtable);
childOID = childrte->relid; childOID = childrte->relid;
/* /*
...@@ -321,12 +322,13 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel, ...@@ -321,12 +322,13 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
* Build the (single) access path for a subquery RTE * Build the (single) access path for a subquery RTE
*/ */
static void static void
set_subquery_pathlist(Query *root, RelOptInfo *rel, set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
Index rti, RangeTblEntry *rte) Index rti, RangeTblEntry *rte)
{ {
Query *subquery = rte->subquery; Query *subquery = rte->subquery;
bool *differentTypes; bool *differentTypes;
List *pathkeys; List *pathkeys;
List *subquery_pathkeys;
/* We need a workspace for keeping track of set-op type coercions */ /* We need a workspace for keeping track of set-op type coercions */
differentTypes = (bool *) differentTypes = (bool *)
...@@ -379,7 +381,8 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel, ...@@ -379,7 +381,8 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel,
pfree(differentTypes); pfree(differentTypes);
/* Generate the plan for the subquery */ /* Generate the plan for the subquery */
rel->subplan = subquery_planner(subquery, 0.0 /* default case */ ); rel->subplan = subquery_planner(subquery, 0.0 /* default case */,
&subquery_pathkeys);
/* Copy number of output rows from subplan */ /* Copy number of output rows from subplan */
rel->tuples = rel->subplan->plan_rows; rel->tuples = rel->subplan->plan_rows;
...@@ -388,7 +391,7 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel, ...@@ -388,7 +391,7 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel,
set_baserel_size_estimates(root, rel); set_baserel_size_estimates(root, rel);
/* Convert subquery pathkeys to outer representation */ /* Convert subquery pathkeys to outer representation */
pathkeys = build_subquery_pathkeys(root, rel, subquery); pathkeys = convert_subquery_pathkeys(root, rel, subquery_pathkeys);
/* Generate appropriate path */ /* Generate appropriate path */
add_path(rel, create_subqueryscan_path(rel, pathkeys)); add_path(rel, create_subqueryscan_path(rel, pathkeys));
...@@ -402,7 +405,7 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel, ...@@ -402,7 +405,7 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel,
* Build the (single) access path for a function RTE * Build the (single) access path for a function RTE
*/ */
static void static void
set_function_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte) set_function_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
{ {
/* Mark rel with estimated output rows, width, etc */ /* Mark rel with estimated output rows, width, etc */
set_function_size_estimates(root, rel); set_function_size_estimates(root, rel);
...@@ -419,7 +422,7 @@ set_function_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte) ...@@ -419,7 +422,7 @@ set_function_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
* Build access paths for a FromExpr jointree node. * Build access paths for a FromExpr jointree node.
*/ */
RelOptInfo * RelOptInfo *
make_fromexpr_rel(Query *root, FromExpr *from) make_fromexpr_rel(PlannerInfo *root, FromExpr *from)
{ {
int levels_needed; int levels_needed;
List *initial_rels = NIL; List *initial_rels = NIL;
...@@ -483,7 +486,7 @@ make_fromexpr_rel(Query *root, FromExpr *from) ...@@ -483,7 +486,7 @@ make_fromexpr_rel(Query *root, FromExpr *from)
* the result of joining all the original relations together. * the result of joining all the original relations together.
*/ */
static RelOptInfo * static RelOptInfo *
make_one_rel_by_joins(Query *root, int levels_needed, List *initial_rels) make_one_rel_by_joins(PlannerInfo *root, int levels_needed, List *initial_rels)
{ {
List **joinitems; List **joinitems;
int lev; int lev;
...@@ -867,7 +870,7 @@ print_relids(Relids relids) ...@@ -867,7 +870,7 @@ print_relids(Relids relids)
} }
static void static void
print_restrictclauses(Query *root, List *clauses) print_restrictclauses(PlannerInfo *root, List *clauses)
{ {
ListCell *l; ListCell *l;
...@@ -875,14 +878,14 @@ print_restrictclauses(Query *root, List *clauses) ...@@ -875,14 +878,14 @@ print_restrictclauses(Query *root, List *clauses)
{ {
RestrictInfo *c = lfirst(l); RestrictInfo *c = lfirst(l);
print_expr((Node *) c->clause, root->rtable); print_expr((Node *) c->clause, root->parse->rtable);
if (lnext(l)) if (lnext(l))
printf(", "); printf(", ");
} }
} }
static void static void
print_path(Query *root, Path *path, int indent) print_path(PlannerInfo *root, Path *path, int indent)
{ {
const char *ptype; const char *ptype;
bool join = false; bool join = false;
...@@ -958,7 +961,7 @@ print_path(Query *root, Path *path, int indent) ...@@ -958,7 +961,7 @@ print_path(Query *root, Path *path, int indent)
for (i = 0; i < indent; i++) for (i = 0; i < indent; i++)
printf("\t"); printf("\t");
printf(" pathkeys: "); printf(" pathkeys: ");
print_pathkeys(path->pathkeys, root->rtable); print_pathkeys(path->pathkeys, root->parse->rtable);
} }
if (join) if (join)
...@@ -994,7 +997,7 @@ print_path(Query *root, Path *path, int indent) ...@@ -994,7 +997,7 @@ print_path(Query *root, Path *path, int indent)
} }
void void
debug_print_rel(Query *root, RelOptInfo *rel) debug_print_rel(PlannerInfo *root, RelOptInfo *rel)
{ {
ListCell *l; ListCell *l;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.72 2004/12/31 22:00:04 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.73 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -92,7 +92,7 @@ static void addRangeClause(RangeQueryClause **rqlist, Node *clause, ...@@ -92,7 +92,7 @@ static void addRangeClause(RangeQueryClause **rqlist, Node *clause,
* scalarltsel/scalargtsel; perhaps some day we can generalize the approach. * scalarltsel/scalargtsel; perhaps some day we can generalize the approach.
*/ */
Selectivity Selectivity
clauselist_selectivity(Query *root, clauselist_selectivity(PlannerInfo *root,
List *clauses, List *clauses,
int varRelid, int varRelid,
JoinType jointype) JoinType jointype)
...@@ -406,7 +406,7 @@ bms_is_subset_singleton(const Bitmapset *s, int x) ...@@ -406,7 +406,7 @@ bms_is_subset_singleton(const Bitmapset *s, int x)
* if the clause isn't a join clause or the context is uncertain. * if the clause isn't a join clause or the context is uncertain.
*/ */
Selectivity Selectivity
clause_selectivity(Query *root, clause_selectivity(PlannerInfo *root,
Node *clause, Node *clause,
int varRelid, int varRelid,
JoinType jointype) JoinType jointype)
...@@ -476,7 +476,7 @@ clause_selectivity(Query *root, ...@@ -476,7 +476,7 @@ clause_selectivity(Query *root,
if (var->varlevelsup == 0 && if (var->varlevelsup == 0 &&
(varRelid == 0 || varRelid == (int) var->varno)) (varRelid == 0 || varRelid == (int) var->varno))
{ {
RangeTblEntry *rte = rt_fetch(var->varno, root->rtable); RangeTblEntry *rte = rt_fetch(var->varno, root->parse->rtable);
if (rte->rtekind == RTE_SUBQUERY) if (rte->rtekind == RTE_SUBQUERY)
{ {
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.145 2005/04/22 21:58:31 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.146 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -104,10 +104,10 @@ bool enable_hashjoin = true; ...@@ -104,10 +104,10 @@ bool enable_hashjoin = true;
static bool cost_qual_eval_walker(Node *node, QualCost *total); static bool cost_qual_eval_walker(Node *node, QualCost *total);
static Selectivity approx_selectivity(Query *root, List *quals, static Selectivity approx_selectivity(PlannerInfo *root, List *quals,
JoinType jointype); JoinType jointype);
static Selectivity join_in_selectivity(JoinPath *path, Query *root); static Selectivity join_in_selectivity(JoinPath *path, PlannerInfo *root);
static void set_rel_width(Query *root, RelOptInfo *rel); static void set_rel_width(PlannerInfo *root, RelOptInfo *rel);
static double relation_byte_size(double tuples, int width); static double relation_byte_size(double tuples, int width);
static double page_size(double tuples, int width); static double page_size(double tuples, int width);
...@@ -138,7 +138,7 @@ clamp_row_est(double nrows) ...@@ -138,7 +138,7 @@ clamp_row_est(double nrows)
* Determines and returns the cost of scanning a relation sequentially. * Determines and returns the cost of scanning a relation sequentially.
*/ */
void void
cost_seqscan(Path *path, Query *root, cost_seqscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel) RelOptInfo *baserel)
{ {
Cost startup_cost = 0; Cost startup_cost = 0;
...@@ -227,7 +227,6 @@ cost_nonsequential_access(double relpages) ...@@ -227,7 +227,6 @@ cost_nonsequential_access(double relpages)
* NOTE: an indexscan plan node can actually represent several passes, * NOTE: an indexscan plan node can actually represent several passes,
* but here we consider the cost of just one pass. * but here we consider the cost of just one pass.
* *
* 'root' is the query root
* 'index' is the index to be used * 'index' is the index to be used
* 'indexQuals' is the list of applicable qual clauses (implicit AND semantics) * 'indexQuals' is the list of applicable qual clauses (implicit AND semantics)
* 'is_injoin' is T if we are considering using the index scan as the inside * 'is_injoin' is T if we are considering using the index scan as the inside
...@@ -246,7 +245,7 @@ cost_nonsequential_access(double relpages) ...@@ -246,7 +245,7 @@ cost_nonsequential_access(double relpages)
* it was a list of bare clause expressions. * it was a list of bare clause expressions.
*/ */
void void
cost_index(IndexPath *path, Query *root, cost_index(IndexPath *path, PlannerInfo *root,
IndexOptInfo *index, IndexOptInfo *index,
List *indexQuals, List *indexQuals,
bool is_injoin) bool is_injoin)
...@@ -418,14 +417,13 @@ cost_index(IndexPath *path, Query *root, ...@@ -418,14 +417,13 @@ cost_index(IndexPath *path, Query *root,
* Determines and returns the cost of scanning a relation using a bitmap * Determines and returns the cost of scanning a relation using a bitmap
* index-then-heap plan. * index-then-heap plan.
* *
* 'root' is the query root
* 'baserel' is the relation to be scanned * 'baserel' is the relation to be scanned
* 'bitmapqual' is a tree of IndexPaths, BitmapAndPaths, and BitmapOrPaths * 'bitmapqual' is a tree of IndexPaths, BitmapAndPaths, and BitmapOrPaths
* 'is_injoin' is T if we are considering using the scan as the inside * 'is_injoin' is T if we are considering using the scan as the inside
* of a nestloop join (hence, some of the quals are join clauses) * of a nestloop join (hence, some of the quals are join clauses)
*/ */
void void
cost_bitmap_heap_scan(Path *path, Query *root, RelOptInfo *baserel, cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
Path *bitmapqual, bool is_injoin) Path *bitmapqual, bool is_injoin)
{ {
Cost startup_cost = 0; Cost startup_cost = 0;
...@@ -534,7 +532,7 @@ cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec) ...@@ -534,7 +532,7 @@ cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
* to warrant treating it as one. * to warrant treating it as one.
*/ */
void void
cost_bitmap_and_node(BitmapAndPath *path, Query *root) cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
{ {
Cost totalCost; Cost totalCost;
Selectivity selec; Selectivity selec;
...@@ -577,7 +575,7 @@ cost_bitmap_and_node(BitmapAndPath *path, Query *root) ...@@ -577,7 +575,7 @@ cost_bitmap_and_node(BitmapAndPath *path, Query *root)
* See comments for cost_bitmap_and_node. * See comments for cost_bitmap_and_node.
*/ */
void void
cost_bitmap_or_node(BitmapOrPath *path, Query *root) cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
{ {
Cost totalCost; Cost totalCost;
Selectivity selec; Selectivity selec;
...@@ -620,7 +618,7 @@ cost_bitmap_or_node(BitmapOrPath *path, Query *root) ...@@ -620,7 +618,7 @@ cost_bitmap_or_node(BitmapOrPath *path, Query *root)
* Determines and returns the cost of scanning a relation using TIDs. * Determines and returns the cost of scanning a relation using TIDs.
*/ */
void void
cost_tidscan(Path *path, Query *root, cost_tidscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, List *tideval) RelOptInfo *baserel, List *tideval)
{ {
Cost startup_cost = 0; Cost startup_cost = 0;
...@@ -684,7 +682,7 @@ cost_subqueryscan(Path *path, RelOptInfo *baserel) ...@@ -684,7 +682,7 @@ cost_subqueryscan(Path *path, RelOptInfo *baserel)
* Determines and returns the cost of scanning a function RTE. * Determines and returns the cost of scanning a function RTE.
*/ */
void void
cost_functionscan(Path *path, Query *root, RelOptInfo *baserel) cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel)
{ {
Cost startup_cost = 0; Cost startup_cost = 0;
Cost run_cost = 0; Cost run_cost = 0;
...@@ -748,7 +746,7 @@ cost_functionscan(Path *path, Query *root, RelOptInfo *baserel) ...@@ -748,7 +746,7 @@ cost_functionscan(Path *path, Query *root, RelOptInfo *baserel)
* of sort keys, which all callers *could* supply.) * of sort keys, which all callers *could* supply.)
*/ */
void void
cost_sort(Path *path, Query *root, cost_sort(Path *path, PlannerInfo *root,
List *pathkeys, Cost input_cost, double tuples, int width) List *pathkeys, Cost input_cost, double tuples, int width)
{ {
Cost startup_cost = input_cost; Cost startup_cost = input_cost;
...@@ -857,7 +855,7 @@ cost_material(Path *path, ...@@ -857,7 +855,7 @@ cost_material(Path *path,
* are for appropriately-sorted input. * are for appropriately-sorted input.
*/ */
void void
cost_agg(Path *path, Query *root, cost_agg(Path *path, PlannerInfo *root,
AggStrategy aggstrategy, int numAggs, AggStrategy aggstrategy, int numAggs,
int numGroupCols, double numGroups, int numGroupCols, double numGroups,
Cost input_startup_cost, Cost input_total_cost, Cost input_startup_cost, Cost input_total_cost,
...@@ -925,7 +923,7 @@ cost_agg(Path *path, Query *root, ...@@ -925,7 +923,7 @@ cost_agg(Path *path, Query *root,
* input. * input.
*/ */
void void
cost_group(Path *path, Query *root, cost_group(Path *path, PlannerInfo *root,
int numGroupCols, double numGroups, int numGroupCols, double numGroups,
Cost input_startup_cost, Cost input_total_cost, Cost input_startup_cost, Cost input_total_cost,
double input_tuples) double input_tuples)
...@@ -954,7 +952,7 @@ cost_group(Path *path, Query *root, ...@@ -954,7 +952,7 @@ cost_group(Path *path, Query *root,
* 'path' is already filled in except for the cost fields * 'path' is already filled in except for the cost fields
*/ */
void void
cost_nestloop(NestPath *path, Query *root) cost_nestloop(NestPath *path, PlannerInfo *root)
{ {
Path *outer_path = path->outerjoinpath; Path *outer_path = path->outerjoinpath;
Path *inner_path = path->innerjoinpath; Path *inner_path = path->innerjoinpath;
...@@ -1046,7 +1044,7 @@ cost_nestloop(NestPath *path, Query *root) ...@@ -1046,7 +1044,7 @@ cost_nestloop(NestPath *path, Query *root)
* sort is needed because the source path is already ordered. * sort is needed because the source path is already ordered.
*/ */
void void
cost_mergejoin(MergePath *path, Query *root) cost_mergejoin(MergePath *path, PlannerInfo *root)
{ {
Path *outer_path = path->jpath.outerjoinpath; Path *outer_path = path->jpath.outerjoinpath;
Path *inner_path = path->jpath.innerjoinpath; Path *inner_path = path->jpath.innerjoinpath;
...@@ -1275,7 +1273,7 @@ cost_mergejoin(MergePath *path, Query *root) ...@@ -1275,7 +1273,7 @@ cost_mergejoin(MergePath *path, Query *root)
* Note: path's hashclauses should be a subset of the joinrestrictinfo list * Note: path's hashclauses should be a subset of the joinrestrictinfo list
*/ */
void void
cost_hashjoin(HashPath *path, Query *root) cost_hashjoin(HashPath *path, PlannerInfo *root)
{ {
Path *outer_path = path->jpath.outerjoinpath; Path *outer_path = path->jpath.outerjoinpath;
Path *inner_path = path->jpath.innerjoinpath; Path *inner_path = path->jpath.innerjoinpath;
...@@ -1673,7 +1671,7 @@ cost_qual_eval_walker(Node *node, QualCost *total) ...@@ -1673,7 +1671,7 @@ cost_qual_eval_walker(Node *node, QualCost *total)
* seems OK to live with the approximation. * seems OK to live with the approximation.
*/ */
static Selectivity static Selectivity
approx_selectivity(Query *root, List *quals, JoinType jointype) approx_selectivity(PlannerInfo *root, List *quals, JoinType jointype)
{ {
Selectivity total = 1.0; Selectivity total = 1.0;
ListCell *l; ListCell *l;
...@@ -1703,7 +1701,7 @@ approx_selectivity(Query *root, List *quals, JoinType jointype) ...@@ -1703,7 +1701,7 @@ approx_selectivity(Query *root, List *quals, JoinType jointype)
* baserestrictcost: estimated cost of evaluating baserestrictinfo clauses. * baserestrictcost: estimated cost of evaluating baserestrictinfo clauses.
*/ */
void void
set_baserel_size_estimates(Query *root, RelOptInfo *rel) set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
{ {
double nrows; double nrows;
...@@ -1749,7 +1747,7 @@ set_baserel_size_estimates(Query *root, RelOptInfo *rel) ...@@ -1749,7 +1747,7 @@ set_baserel_size_estimates(Query *root, RelOptInfo *rel)
* build_joinrel_tlist, and baserestrictcost is not used for join rels. * build_joinrel_tlist, and baserestrictcost is not used for join rels.
*/ */
void void
set_joinrel_size_estimates(Query *root, RelOptInfo *rel, set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
RelOptInfo *outer_rel, RelOptInfo *outer_rel,
RelOptInfo *inner_rel, RelOptInfo *inner_rel,
JoinType jointype, JoinType jointype,
...@@ -1836,7 +1834,7 @@ set_joinrel_size_estimates(Query *root, RelOptInfo *rel, ...@@ -1836,7 +1834,7 @@ set_joinrel_size_estimates(Query *root, RelOptInfo *rel,
* 'path' is already filled in except for the cost fields * 'path' is already filled in except for the cost fields
*/ */
static Selectivity static Selectivity
join_in_selectivity(JoinPath *path, Query *root) join_in_selectivity(JoinPath *path, PlannerInfo *root)
{ {
RelOptInfo *innerrel; RelOptInfo *innerrel;
UniquePath *innerunique; UniquePath *innerunique;
...@@ -1896,7 +1894,7 @@ join_in_selectivity(JoinPath *path, Query *root) ...@@ -1896,7 +1894,7 @@ join_in_selectivity(JoinPath *path, Query *root)
* We set the same fields as set_baserel_size_estimates. * We set the same fields as set_baserel_size_estimates.
*/ */
void void
set_function_size_estimates(Query *root, RelOptInfo *rel) set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel)
{ {
/* Should only be applied to base relations that are functions */ /* Should only be applied to base relations that are functions */
Assert(rel->relid > 0); Assert(rel->relid > 0);
...@@ -1929,7 +1927,7 @@ set_function_size_estimates(Query *root, RelOptInfo *rel) ...@@ -1929,7 +1927,7 @@ set_function_size_estimates(Query *root, RelOptInfo *rel)
* building join relations. * building join relations.
*/ */
static void static void
set_rel_width(Query *root, RelOptInfo *rel) set_rel_width(PlannerInfo *root, RelOptInfo *rel)
{ {
int32 tuple_width = 0; int32 tuple_width = 0;
ListCell *tllist; ListCell *tllist;
...@@ -1960,7 +1958,7 @@ set_rel_width(Query *root, RelOptInfo *rel) ...@@ -1960,7 +1958,7 @@ set_rel_width(Query *root, RelOptInfo *rel)
continue; continue;
} }
relid = getrelid(var->varno, root->rtable); relid = getrelid(var->varno, root->parse->rtable);
if (relid != InvalidOid) if (relid != InvalidOid)
{ {
item_width = get_attavgwidth(relid, var->varattno); item_width = get_attavgwidth(relid, var->varattno);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.180 2005/05/06 17:24:54 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.181 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -55,13 +55,13 @@ ...@@ -55,13 +55,13 @@
((opclass) == BOOL_BTREE_OPS_OID || (opclass) == BOOL_HASH_OPS_OID) ((opclass) == BOOL_BTREE_OPS_OID || (opclass) == BOOL_HASH_OPS_OID)
static List *find_usable_indexes(Query *root, RelOptInfo *rel, static List *find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
List *clauses, List *outer_clauses, List *clauses, List *outer_clauses,
bool istoplevel, bool isjoininner, bool istoplevel, bool isjoininner,
Relids outer_relids); Relids outer_relids);
static Path *choose_bitmap_and(Query *root, RelOptInfo *rel, List *paths); static Path *choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel, List *paths);
static int bitmap_path_comparator(const void *a, const void *b); static int bitmap_path_comparator(const void *a, const void *b);
static Cost bitmap_and_cost_est(Query *root, RelOptInfo *rel, List *paths); static Cost bitmap_and_cost_est(PlannerInfo *root, RelOptInfo *rel, List *paths);
static bool match_clause_to_indexcol(IndexOptInfo *index, static bool match_clause_to_indexcol(IndexOptInfo *index,
int indexcol, Oid opclass, int indexcol, Oid opclass,
RestrictInfo *rinfo, RestrictInfo *rinfo,
...@@ -75,7 +75,7 @@ static bool list_matches_any_index(List *clauses, RelOptInfo *rel, ...@@ -75,7 +75,7 @@ static bool list_matches_any_index(List *clauses, RelOptInfo *rel,
Relids outer_relids); Relids outer_relids);
static bool matches_any_index(RestrictInfo *rinfo, RelOptInfo *rel, static bool matches_any_index(RestrictInfo *rinfo, RelOptInfo *rel,
Relids outer_relids); Relids outer_relids);
static List *find_clauses_for_join(Query *root, RelOptInfo *rel, static List *find_clauses_for_join(PlannerInfo *root, RelOptInfo *rel,
Relids outer_relids, bool isouterjoin); Relids outer_relids, bool isouterjoin);
static bool match_boolean_index_clause(Node *clause, int indexcol, static bool match_boolean_index_clause(Node *clause, int indexcol,
IndexOptInfo *index); IndexOptInfo *index);
...@@ -124,7 +124,7 @@ static Const *string_to_const(const char *str, Oid datatype); ...@@ -124,7 +124,7 @@ static Const *string_to_const(const char *str, Oid datatype);
* Note: check_partial_indexes() must have been run previously. * Note: check_partial_indexes() must have been run previously.
*/ */
void void
create_index_paths(Query *root, RelOptInfo *rel) create_index_paths(PlannerInfo *root, RelOptInfo *rel)
{ {
List *indexpaths; List *indexpaths;
List *bitindexpaths; List *bitindexpaths;
...@@ -231,7 +231,7 @@ create_index_paths(Query *root, RelOptInfo *rel) ...@@ -231,7 +231,7 @@ create_index_paths(Query *root, RelOptInfo *rel)
*---------- *----------
*/ */
static List * static List *
find_usable_indexes(Query *root, RelOptInfo *rel, find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
List *clauses, List *outer_clauses, List *clauses, List *outer_clauses,
bool istoplevel, bool isjoininner, bool istoplevel, bool isjoininner,
Relids outer_relids) Relids outer_relids)
...@@ -363,7 +363,7 @@ find_usable_indexes(Query *root, RelOptInfo *rel, ...@@ -363,7 +363,7 @@ find_usable_indexes(Query *root, RelOptInfo *rel,
* ORs. (See find_usable_indexes() for motivation.) * ORs. (See find_usable_indexes() for motivation.)
*/ */
List * List *
generate_bitmap_or_paths(Query *root, RelOptInfo *rel, generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
List *clauses, List *outer_clauses, List *clauses, List *outer_clauses,
bool isjoininner, bool isjoininner,
Relids outer_relids) Relids outer_relids)
...@@ -473,7 +473,7 @@ generate_bitmap_or_paths(Query *root, RelOptInfo *rel, ...@@ -473,7 +473,7 @@ generate_bitmap_or_paths(Query *root, RelOptInfo *rel,
* combining multiple inputs. * combining multiple inputs.
*/ */
static Path * static Path *
choose_bitmap_and(Query *root, RelOptInfo *rel, List *paths) choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel, List *paths)
{ {
int npaths = list_length(paths); int npaths = list_length(paths);
Path **patharray; Path **patharray;
...@@ -593,7 +593,7 @@ bitmap_path_comparator(const void *a, const void *b) ...@@ -593,7 +593,7 @@ bitmap_path_comparator(const void *a, const void *b)
* inputs. * inputs.
*/ */
static Cost static Cost
bitmap_and_cost_est(Query *root, RelOptInfo *rel, List *paths) bitmap_and_cost_est(PlannerInfo *root, RelOptInfo *rel, List *paths)
{ {
BitmapAndPath apath; BitmapAndPath apath;
Path bpath; Path bpath;
...@@ -864,7 +864,7 @@ indexable_operator(Expr *clause, Oid opclass, bool indexkey_on_left) ...@@ -864,7 +864,7 @@ indexable_operator(Expr *clause, Oid opclass, bool indexkey_on_left)
* depending on whether the predicate is satisfied for this query. * depending on whether the predicate is satisfied for this query.
*/ */
void void
check_partial_indexes(Query *root, RelOptInfo *rel) check_partial_indexes(PlannerInfo *root, RelOptInfo *rel)
{ {
List *restrictinfo_list = rel->baserestrictinfo; List *restrictinfo_list = rel->baserestrictinfo;
ListCell *ilist; ListCell *ilist;
...@@ -1675,7 +1675,7 @@ matches_any_index(RestrictInfo *rinfo, RelOptInfo *rel, Relids outer_relids) ...@@ -1675,7 +1675,7 @@ matches_any_index(RestrictInfo *rinfo, RelOptInfo *rel, Relids outer_relids)
* sufficient to return a single "best" path. * sufficient to return a single "best" path.
*/ */
Path * Path *
best_inner_indexscan(Query *root, RelOptInfo *rel, best_inner_indexscan(PlannerInfo *root, RelOptInfo *rel,
Relids outer_relids, JoinType jointype) Relids outer_relids, JoinType jointype)
{ {
Path *cheapest; Path *cheapest;
...@@ -1828,7 +1828,7 @@ best_inner_indexscan(Query *root, RelOptInfo *rel, ...@@ -1828,7 +1828,7 @@ best_inner_indexscan(Query *root, RelOptInfo *rel,
* indicating that there isn't any potential win here. * indicating that there isn't any potential win here.
*/ */
static List * static List *
find_clauses_for_join(Query *root, RelOptInfo *rel, find_clauses_for_join(PlannerInfo *root, RelOptInfo *rel,
Relids outer_relids, bool isouterjoin) Relids outer_relids, bool isouterjoin)
{ {
List *clause_list = NIL; List *clause_list = NIL;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.94 2005/05/24 18:02:31 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.95 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -24,15 +24,15 @@ ...@@ -24,15 +24,15 @@
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
static void sort_inner_and_outer(Query *root, RelOptInfo *joinrel, static void sort_inner_and_outer(PlannerInfo *root, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *innerrel, RelOptInfo *outerrel, RelOptInfo *innerrel,
List *restrictlist, List *mergeclause_list, List *restrictlist, List *mergeclause_list,
JoinType jointype); JoinType jointype);
static void match_unsorted_outer(Query *root, RelOptInfo *joinrel, static void match_unsorted_outer(PlannerInfo *root, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *innerrel, RelOptInfo *outerrel, RelOptInfo *innerrel,
List *restrictlist, List *mergeclause_list, List *restrictlist, List *mergeclause_list,
JoinType jointype); JoinType jointype);
static void hash_inner_and_outer(Query *root, RelOptInfo *joinrel, static void hash_inner_and_outer(PlannerInfo *root, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *innerrel, RelOptInfo *outerrel, RelOptInfo *innerrel,
List *restrictlist, JoinType jointype); List *restrictlist, JoinType jointype);
static List *select_mergejoin_clauses(RelOptInfo *joinrel, static List *select_mergejoin_clauses(RelOptInfo *joinrel,
...@@ -54,7 +54,7 @@ static List *select_mergejoin_clauses(RelOptInfo *joinrel, ...@@ -54,7 +54,7 @@ static List *select_mergejoin_clauses(RelOptInfo *joinrel,
* paths found so far. * paths found so far.
*/ */
void void
add_paths_to_joinrel(Query *root, add_paths_to_joinrel(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *outerrel,
RelOptInfo *innerrel, RelOptInfo *innerrel,
...@@ -133,7 +133,7 @@ add_paths_to_joinrel(Query *root, ...@@ -133,7 +133,7 @@ add_paths_to_joinrel(Query *root,
* 'jointype' is the type of join to do * 'jointype' is the type of join to do
*/ */
static void static void
sort_inner_and_outer(Query *root, sort_inner_and_outer(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *outerrel,
RelOptInfo *innerrel, RelOptInfo *innerrel,
...@@ -324,7 +324,7 @@ sort_inner_and_outer(Query *root, ...@@ -324,7 +324,7 @@ sort_inner_and_outer(Query *root,
* 'jointype' is the type of join to do * 'jointype' is the type of join to do
*/ */
static void static void
match_unsorted_outer(Query *root, match_unsorted_outer(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *outerrel,
RelOptInfo *innerrel, RelOptInfo *innerrel,
...@@ -664,7 +664,7 @@ match_unsorted_outer(Query *root, ...@@ -664,7 +664,7 @@ match_unsorted_outer(Query *root,
* 'jointype' is the type of join to do * 'jointype' is the type of join to do
*/ */
static void static void
hash_inner_and_outer(Query *root, hash_inner_and_outer(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *outerrel,
RelOptInfo *innerrel, RelOptInfo *innerrel,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.72 2004/12/31 22:00:04 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/joinrels.c,v 1.73 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
#include "optimizer/paths.h" #include "optimizer/paths.h"
static List *make_rels_by_clause_joins(Query *root, static List *make_rels_by_clause_joins(PlannerInfo *root,
RelOptInfo *old_rel, RelOptInfo *old_rel,
ListCell *other_rels); ListCell *other_rels);
static List *make_rels_by_clauseless_joins(Query *root, static List *make_rels_by_clauseless_joins(PlannerInfo *root,
RelOptInfo *old_rel, RelOptInfo *old_rel,
ListCell *other_rels); ListCell *other_rels);
static bool is_inside_IN(Query *root, RelOptInfo *rel); static bool is_inside_IN(PlannerInfo *root, RelOptInfo *rel);
/* /*
...@@ -39,7 +39,7 @@ static bool is_inside_IN(Query *root, RelOptInfo *rel); ...@@ -39,7 +39,7 @@ static bool is_inside_IN(Query *root, RelOptInfo *rel);
* joinrels[j], 1 <= j < level, is a list of rels containing j items. * joinrels[j], 1 <= j < level, is a list of rels containing j items.
*/ */
List * List *
make_rels_by_joins(Query *root, int level, List **joinrels) make_rels_by_joins(PlannerInfo *root, int level, List **joinrels)
{ {
List *result_rels = NIL; List *result_rels = NIL;
List *new_rels; List *new_rels;
...@@ -284,7 +284,7 @@ make_rels_by_joins(Query *root, int level, List **joinrels) ...@@ -284,7 +284,7 @@ make_rels_by_joins(Query *root, int level, List **joinrels)
* only succeed when other_rel is not already part of old_rel.) * only succeed when other_rel is not already part of old_rel.)
*/ */
static List * static List *
make_rels_by_clause_joins(Query *root, make_rels_by_clause_joins(PlannerInfo *root,
RelOptInfo *old_rel, RelOptInfo *old_rel,
ListCell *other_rels) ListCell *other_rels)
{ {
...@@ -335,7 +335,7 @@ make_rels_by_clause_joins(Query *root, ...@@ -335,7 +335,7 @@ make_rels_by_clause_joins(Query *root,
* work for joining to joinrels too. * work for joining to joinrels too.
*/ */
static List * static List *
make_rels_by_clauseless_joins(Query *root, make_rels_by_clauseless_joins(PlannerInfo *root,
RelOptInfo *old_rel, RelOptInfo *old_rel,
ListCell *other_rels) ListCell *other_rels)
{ {
...@@ -373,7 +373,7 @@ make_rels_by_clauseless_joins(Query *root, ...@@ -373,7 +373,7 @@ make_rels_by_clauseless_joins(Query *root,
* out of an IN, so the routine name is a slight misnomer. * out of an IN, so the routine name is a slight misnomer.
*/ */
static bool static bool
is_inside_IN(Query *root, RelOptInfo *rel) is_inside_IN(PlannerInfo *root, RelOptInfo *rel)
{ {
ListCell *l; ListCell *l;
...@@ -395,7 +395,7 @@ is_inside_IN(Query *root, RelOptInfo *rel) ...@@ -395,7 +395,7 @@ is_inside_IN(Query *root, RelOptInfo *rel)
* path that corresponds exactly to what the user wrote. * path that corresponds exactly to what the user wrote.
*/ */
RelOptInfo * RelOptInfo *
make_jointree_rel(Query *root, Node *jtnode) make_jointree_rel(PlannerInfo *root, Node *jtnode)
{ {
if (IsA(jtnode, RangeTblRef)) if (IsA(jtnode, RangeTblRef))
{ {
...@@ -460,7 +460,7 @@ make_jointree_rel(Query *root, Node *jtnode) ...@@ -460,7 +460,7 @@ make_jointree_rel(Query *root, Node *jtnode)
* happen when working with IN clauses that have been turned into joins. * happen when working with IN clauses that have been turned into joins.
*/ */
RelOptInfo * RelOptInfo *
make_join_rel(Query *root, RelOptInfo *rel1, RelOptInfo *rel2, make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
JoinType jointype) JoinType jointype)
{ {
Relids joinrelids; Relids joinrelids;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.70 2005/04/25 02:14:47 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/orindxpath.c,v 1.71 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
*---------- *----------
*/ */
bool bool
create_or_index_quals(Query *root, RelOptInfo *rel) create_or_index_quals(PlannerInfo *root, RelOptInfo *rel)
{ {
BitmapOrPath *bestpath = NULL; BitmapOrPath *bestpath = NULL;
RestrictInfo *bestrinfo = NULL; RestrictInfo *bestrinfo = NULL;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.66 2005/04/06 16:34:05 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.67 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
static PathKeyItem *makePathKeyItem(Node *key, Oid sortop, bool checkType); static PathKeyItem *makePathKeyItem(Node *key, Oid sortop, bool checkType);
static List *make_canonical_pathkey(Query *root, PathKeyItem *item); static List *make_canonical_pathkey(PlannerInfo *root, PathKeyItem *item);
static Var *find_indexkey_var(Query *root, RelOptInfo *rel, static Var *find_indexkey_var(PlannerInfo *root, RelOptInfo *rel,
AttrNumber varattno); AttrNumber varattno);
...@@ -87,7 +87,7 @@ makePathKeyItem(Node *key, Oid sortop, bool checkType) ...@@ -87,7 +87,7 @@ makePathKeyItem(Node *key, Oid sortop, bool checkType)
* that involves an equijoined variable. * that involves an equijoined variable.
*/ */
void void
add_equijoined_keys(Query *root, RestrictInfo *restrictinfo) add_equijoined_keys(PlannerInfo *root, RestrictInfo *restrictinfo)
{ {
Expr *clause = restrictinfo->clause; Expr *clause = restrictinfo->clause;
PathKeyItem *item1 = makePathKeyItem(get_leftop(clause), PathKeyItem *item1 = makePathKeyItem(get_leftop(clause),
...@@ -198,7 +198,7 @@ add_equijoined_keys(Query *root, RestrictInfo *restrictinfo) ...@@ -198,7 +198,7 @@ add_equijoined_keys(Query *root, RestrictInfo *restrictinfo)
* restrictinfo datastructures for each pair. * restrictinfo datastructures for each pair.
*/ */
void void
generate_implied_equalities(Query *root) generate_implied_equalities(PlannerInfo *root)
{ {
ListCell *cursetlink; ListCell *cursetlink;
...@@ -293,7 +293,7 @@ generate_implied_equalities(Query *root) ...@@ -293,7 +293,7 @@ generate_implied_equalities(Query *root)
* check that case if it's possible to pass identical items. * check that case if it's possible to pass identical items.
*/ */
bool bool
exprs_known_equal(Query *root, Node *item1, Node *item2) exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2)
{ {
ListCell *cursetlink; ListCell *cursetlink;
...@@ -333,7 +333,7 @@ exprs_known_equal(Query *root, Node *item1, Node *item2) ...@@ -333,7 +333,7 @@ exprs_known_equal(Query *root, Node *item1, Node *item2)
* scanning the WHERE clause for equijoin operators. * scanning the WHERE clause for equijoin operators.
*/ */
static List * static List *
make_canonical_pathkey(Query *root, PathKeyItem *item) make_canonical_pathkey(PlannerInfo *root, PathKeyItem *item)
{ {
List *newset; List *newset;
ListCell *cursetlink; ListCell *cursetlink;
...@@ -358,7 +358,7 @@ make_canonical_pathkey(Query *root, PathKeyItem *item) ...@@ -358,7 +358,7 @@ make_canonical_pathkey(Query *root, PathKeyItem *item)
* scanning the WHERE clause for equijoin operators. * scanning the WHERE clause for equijoin operators.
*/ */
List * List *
canonicalize_pathkeys(Query *root, List *pathkeys) canonicalize_pathkeys(PlannerInfo *root, List *pathkeys)
{ {
List *new_pathkeys = NIL; List *new_pathkeys = NIL;
ListCell *l; ListCell *l;
...@@ -398,10 +398,10 @@ canonicalize_pathkeys(Query *root, List *pathkeys) ...@@ -398,10 +398,10 @@ canonicalize_pathkeys(Query *root, List *pathkeys)
* If not, return 0 (without actually adding it to our equi_key_list). * If not, return 0 (without actually adding it to our equi_key_list).
* *
* This is a hack to support the rather bogus heuristics in * This is a hack to support the rather bogus heuristics in
* build_subquery_pathkeys. * convert_subquery_pathkeys.
*/ */
static int static int
count_canonical_peers(Query *root, PathKeyItem *item) count_canonical_peers(PlannerInfo *root, PathKeyItem *item)
{ {
ListCell *cursetlink; ListCell *cursetlink;
...@@ -441,7 +441,7 @@ compare_pathkeys(List *keys1, List *keys2) ...@@ -441,7 +441,7 @@ compare_pathkeys(List *keys1, List *keys2)
/* /*
* XXX would like to check that we've been given canonicalized * XXX would like to check that we've been given canonicalized
* input, but query root not accessible here... * input, but PlannerInfo not accessible here...
*/ */
#ifdef NOT_USED #ifdef NOT_USED
Assert(list_member_ptr(root->equi_key_list, subkey1)); Assert(list_member_ptr(root->equi_key_list, subkey1));
...@@ -647,7 +647,7 @@ get_cheapest_fractional_path_for_pathkeys(List *paths, ...@@ -647,7 +647,7 @@ get_cheapest_fractional_path_for_pathkeys(List *paths,
* current query. Caller should do truncate_useless_pathkeys(). * current query. Caller should do truncate_useless_pathkeys().
*/ */
List * List *
build_index_pathkeys(Query *root, build_index_pathkeys(PlannerInfo *root,
IndexOptInfo *index, IndexOptInfo *index,
ScanDirection scandir) ScanDirection scandir)
{ {
...@@ -714,7 +714,7 @@ build_index_pathkeys(Query *root, ...@@ -714,7 +714,7 @@ build_index_pathkeys(Query *root,
* gin up a Var node the hard way. * gin up a Var node the hard way.
*/ */
static Var * static Var *
find_indexkey_var(Query *root, RelOptInfo *rel, AttrNumber varattno) find_indexkey_var(PlannerInfo *root, RelOptInfo *rel, AttrNumber varattno)
{ {
ListCell *temp; ListCell *temp;
Index relid; Index relid;
...@@ -732,24 +732,28 @@ find_indexkey_var(Query *root, RelOptInfo *rel, AttrNumber varattno) ...@@ -732,24 +732,28 @@ find_indexkey_var(Query *root, RelOptInfo *rel, AttrNumber varattno)
} }
relid = rel->relid; relid = rel->relid;
reloid = getrelid(relid, root->rtable); reloid = getrelid(relid, root->parse->rtable);
get_atttypetypmod(reloid, varattno, &vartypeid, &type_mod); get_atttypetypmod(reloid, varattno, &vartypeid, &type_mod);
return makeVar(relid, varattno, vartypeid, type_mod, 0); return makeVar(relid, varattno, vartypeid, type_mod, 0);
} }
/* /*
* build_subquery_pathkeys * convert_subquery_pathkeys
* Build a pathkeys list that describes the ordering of a subquery's * Build a pathkeys list that describes the ordering of a subquery's
* result (in the terms of the outer query). The subquery must already * result, in the terms of the outer query. This is essentially a
* have been planned, so that its query_pathkeys field has been set. * task of conversion.
*
* 'rel': outer query's RelOptInfo for the subquery relation.
* 'subquery_pathkeys': the subquery's output pathkeys, in its terms.
* *
* It is not necessary for caller to do truncate_useless_pathkeys(), * It is not necessary for caller to do truncate_useless_pathkeys(),
* because we select keys in a way that takes usefulness of the keys into * because we select keys in a way that takes usefulness of the keys into
* account. * account.
*/ */
List * List *
build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery) convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
List *subquery_pathkeys)
{ {
List *retval = NIL; List *retval = NIL;
int retvallen = 0; int retvallen = 0;
...@@ -757,7 +761,7 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery) ...@@ -757,7 +761,7 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
List *sub_tlist = rel->subplan->targetlist; List *sub_tlist = rel->subplan->targetlist;
ListCell *i; ListCell *i;
foreach(i, subquery->query_pathkeys) foreach(i, subquery_pathkeys)
{ {
List *sub_pathkey = (List *) lfirst(i); List *sub_pathkey = (List *) lfirst(i);
ListCell *j; ListCell *j;
...@@ -869,7 +873,7 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery) ...@@ -869,7 +873,7 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
* Returns the list of new path keys. * Returns the list of new path keys.
*/ */
List * List *
build_join_pathkeys(Query *root, build_join_pathkeys(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
JoinType jointype, JoinType jointype,
List *outer_pathkeys) List *outer_pathkeys)
...@@ -954,7 +958,7 @@ make_pathkeys_for_sortclauses(List *sortclauses, ...@@ -954,7 +958,7 @@ make_pathkeys_for_sortclauses(List *sortclauses,
* problem for normal planning, but it is an issue for GEQO planning. * problem for normal planning, but it is an issue for GEQO planning.
*/ */
void void
cache_mergeclause_pathkeys(Query *root, RestrictInfo *restrictinfo) cache_mergeclause_pathkeys(PlannerInfo *root, RestrictInfo *restrictinfo)
{ {
Node *key; Node *key;
PathKeyItem *item; PathKeyItem *item;
...@@ -1000,7 +1004,7 @@ cache_mergeclause_pathkeys(Query *root, RestrictInfo *restrictinfo) ...@@ -1000,7 +1004,7 @@ cache_mergeclause_pathkeys(Query *root, RestrictInfo *restrictinfo)
* of the join. * of the join.
*/ */
List * List *
find_mergeclauses_for_pathkeys(Query *root, find_mergeclauses_for_pathkeys(PlannerInfo *root,
List *pathkeys, List *pathkeys,
List *restrictinfos) List *restrictinfos)
{ {
...@@ -1093,7 +1097,7 @@ find_mergeclauses_for_pathkeys(Query *root, ...@@ -1093,7 +1097,7 @@ find_mergeclauses_for_pathkeys(Query *root,
* just make the keys, eh? * just make the keys, eh?
*/ */
List * List *
make_pathkeys_for_mergeclauses(Query *root, make_pathkeys_for_mergeclauses(PlannerInfo *root,
List *mergeclauses, List *mergeclauses,
RelOptInfo *rel) RelOptInfo *rel)
{ {
...@@ -1162,7 +1166,7 @@ make_pathkeys_for_mergeclauses(Query *root, ...@@ -1162,7 +1166,7 @@ make_pathkeys_for_mergeclauses(Query *root,
* to be more trouble than it's worth. * to be more trouble than it's worth.
*/ */
int int
pathkeys_useful_for_merging(Query *root, RelOptInfo *rel, List *pathkeys) pathkeys_useful_for_merging(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
{ {
int useful = 0; int useful = 0;
ListCell *i; ListCell *i;
...@@ -1226,7 +1230,7 @@ pathkeys_useful_for_merging(Query *root, RelOptInfo *rel, List *pathkeys) ...@@ -1226,7 +1230,7 @@ pathkeys_useful_for_merging(Query *root, RelOptInfo *rel, List *pathkeys)
* So the result is always either 0 or list_length(root->query_pathkeys). * So the result is always either 0 or list_length(root->query_pathkeys).
*/ */
int int
pathkeys_useful_for_ordering(Query *root, List *pathkeys) pathkeys_useful_for_ordering(PlannerInfo *root, List *pathkeys)
{ {
if (root->query_pathkeys == NIL) if (root->query_pathkeys == NIL)
return 0; /* no special ordering requested */ return 0; /* no special ordering requested */
...@@ -1248,7 +1252,7 @@ pathkeys_useful_for_ordering(Query *root, List *pathkeys) ...@@ -1248,7 +1252,7 @@ pathkeys_useful_for_ordering(Query *root, List *pathkeys)
* Shorten the given pathkey list to just the useful pathkeys. * Shorten the given pathkey list to just the useful pathkeys.
*/ */
List * List *
truncate_useless_pathkeys(Query *root, truncate_useless_pathkeys(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
List *pathkeys) List *pathkeys)
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/path/tidpath.c,v 1.22 2004/12/31 22:00:04 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/path/tidpath.c,v 1.23 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -25,11 +25,13 @@ ...@@ -25,11 +25,13 @@
#include "parser/parse_coerce.h" #include "parser/parse_coerce.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
static List *TidqualFromRestrictinfo(Relids relids, List *restrictinfo); static List *TidqualFromRestrictinfo(Relids relids, List *restrictinfo);
static bool isEvaluable(int varno, Node *node); static bool isEvaluable(int varno, Node *node);
static Node *TidequalClause(int varno, OpExpr *node); static Node *TidequalClause(int varno, OpExpr *node);
static List *TidqualFromExpr(int varno, Expr *expr); static List *TidqualFromExpr(int varno, Expr *expr);
static bool static bool
isEvaluable(int varno, Node *node) isEvaluable(int varno, Node *node)
{ {
...@@ -228,7 +230,7 @@ TidqualFromRestrictinfo(Relids relids, List *restrictinfo) ...@@ -228,7 +230,7 @@ TidqualFromRestrictinfo(Relids relids, List *restrictinfo)
* Candidate paths are added to the rel's pathlist (using add_path). * Candidate paths are added to the rel's pathlist (using add_path).
*/ */
void void
create_tidscan_paths(Query *root, RelOptInfo *rel) create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel)
{ {
List *tideval = TidqualFromRestrictinfo(rel->relids, List *tideval = TidqualFromRestrictinfo(rel->relids,
rel->baserestrictinfo); rel->baserestrictinfo);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.190 2005/05/30 18:55:49 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.191 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -35,36 +35,36 @@ ...@@ -35,36 +35,36 @@
#include "utils/syscache.h" #include "utils/syscache.h"
static Scan *create_scan_plan(Query *root, Path *best_path); static Scan *create_scan_plan(PlannerInfo *root, Path *best_path);
static List *build_relation_tlist(RelOptInfo *rel); static List *build_relation_tlist(RelOptInfo *rel);
static bool use_physical_tlist(RelOptInfo *rel); static bool use_physical_tlist(RelOptInfo *rel);
static void disuse_physical_tlist(Plan *plan, Path *path); static void disuse_physical_tlist(Plan *plan, Path *path);
static Join *create_join_plan(Query *root, JoinPath *best_path); static Join *create_join_plan(PlannerInfo *root, JoinPath *best_path);
static Append *create_append_plan(Query *root, AppendPath *best_path); static Append *create_append_plan(PlannerInfo *root, AppendPath *best_path);
static Result *create_result_plan(Query *root, ResultPath *best_path); static Result *create_result_plan(PlannerInfo *root, ResultPath *best_path);
static Material *create_material_plan(Query *root, MaterialPath *best_path); static Material *create_material_plan(PlannerInfo *root, MaterialPath *best_path);
static Plan *create_unique_plan(Query *root, UniquePath *best_path); static Plan *create_unique_plan(PlannerInfo *root, UniquePath *best_path);
static SeqScan *create_seqscan_plan(Query *root, Path *best_path, static SeqScan *create_seqscan_plan(PlannerInfo *root, Path *best_path,
List *tlist, List *scan_clauses); List *tlist, List *scan_clauses);
static IndexScan *create_indexscan_plan(Query *root, IndexPath *best_path, static IndexScan *create_indexscan_plan(PlannerInfo *root, IndexPath *best_path,
List *tlist, List *scan_clauses, List *tlist, List *scan_clauses,
List **nonlossy_clauses); List **nonlossy_clauses);
static BitmapHeapScan *create_bitmap_scan_plan(Query *root, static BitmapHeapScan *create_bitmap_scan_plan(PlannerInfo *root,
BitmapHeapPath *best_path, BitmapHeapPath *best_path,
List *tlist, List *scan_clauses); List *tlist, List *scan_clauses);
static Plan *create_bitmap_subplan(Query *root, Path *bitmapqual, static Plan *create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,
List **qual, List **indexqual); List **qual, List **indexqual);
static TidScan *create_tidscan_plan(Query *root, TidPath *best_path, static TidScan *create_tidscan_plan(PlannerInfo *root, TidPath *best_path,
List *tlist, List *scan_clauses); List *tlist, List *scan_clauses);
static SubqueryScan *create_subqueryscan_plan(Query *root, Path *best_path, static SubqueryScan *create_subqueryscan_plan(PlannerInfo *root, Path *best_path,
List *tlist, List *scan_clauses); List *tlist, List *scan_clauses);
static FunctionScan *create_functionscan_plan(Query *root, Path *best_path, static FunctionScan *create_functionscan_plan(PlannerInfo *root, Path *best_path,
List *tlist, List *scan_clauses); List *tlist, List *scan_clauses);
static NestLoop *create_nestloop_plan(Query *root, NestPath *best_path, static NestLoop *create_nestloop_plan(PlannerInfo *root, NestPath *best_path,
Plan *outer_plan, Plan *inner_plan); Plan *outer_plan, Plan *inner_plan);
static MergeJoin *create_mergejoin_plan(Query *root, MergePath *best_path, static MergeJoin *create_mergejoin_plan(PlannerInfo *root, MergePath *best_path,
Plan *outer_plan, Plan *inner_plan); Plan *outer_plan, Plan *inner_plan);
static HashJoin *create_hashjoin_plan(Query *root, HashPath *best_path, static HashJoin *create_hashjoin_plan(PlannerInfo *root, HashPath *best_path,
Plan *outer_plan, Plan *inner_plan); Plan *outer_plan, Plan *inner_plan);
static void fix_indexqual_references(List *indexquals, IndexPath *index_path, static void fix_indexqual_references(List *indexquals, IndexPath *index_path,
List **fixed_indexquals, List **fixed_indexquals,
...@@ -112,9 +112,9 @@ static MergeJoin *make_mergejoin(List *tlist, ...@@ -112,9 +112,9 @@ static MergeJoin *make_mergejoin(List *tlist,
List *mergeclauses, List *mergeclauses,
Plan *lefttree, Plan *righttree, Plan *lefttree, Plan *righttree,
JoinType jointype); JoinType jointype);
static Sort *make_sort(Query *root, Plan *lefttree, int numCols, static Sort *make_sort(PlannerInfo *root, Plan *lefttree, int numCols,
AttrNumber *sortColIdx, Oid *sortOperators); AttrNumber *sortColIdx, Oid *sortOperators);
static Sort *make_sort_from_pathkeys(Query *root, Plan *lefttree, static Sort *make_sort_from_pathkeys(PlannerInfo *root, Plan *lefttree,
List *pathkeys); List *pathkeys);
...@@ -134,7 +134,7 @@ static Sort *make_sort_from_pathkeys(Query *root, Plan *lefttree, ...@@ -134,7 +134,7 @@ static Sort *make_sort_from_pathkeys(Query *root, Plan *lefttree,
* Returns a Plan tree. * Returns a Plan tree.
*/ */
Plan * Plan *
create_plan(Query *root, Path *best_path) create_plan(PlannerInfo *root, Path *best_path)
{ {
Plan *plan; Plan *plan;
...@@ -187,7 +187,7 @@ create_plan(Query *root, Path *best_path) ...@@ -187,7 +187,7 @@ create_plan(Query *root, Path *best_path)
* Returns a Plan node. * Returns a Plan node.
*/ */
static Scan * static Scan *
create_scan_plan(Query *root, Path *best_path) create_scan_plan(PlannerInfo *root, Path *best_path)
{ {
RelOptInfo *rel = best_path->parent; RelOptInfo *rel = best_path->parent;
List *tlist; List *tlist;
...@@ -376,7 +376,7 @@ disuse_physical_tlist(Plan *plan, Path *path) ...@@ -376,7 +376,7 @@ disuse_physical_tlist(Plan *plan, Path *path)
* Returns a Plan node. * Returns a Plan node.
*/ */
static Join * static Join *
create_join_plan(Query *root, JoinPath *best_path) create_join_plan(PlannerInfo *root, JoinPath *best_path)
{ {
Plan *outer_plan; Plan *outer_plan;
Plan *inner_plan; Plan *inner_plan;
...@@ -436,7 +436,7 @@ create_join_plan(Query *root, JoinPath *best_path) ...@@ -436,7 +436,7 @@ create_join_plan(Query *root, JoinPath *best_path)
* Returns a Plan node. * Returns a Plan node.
*/ */
static Append * static Append *
create_append_plan(Query *root, AppendPath *best_path) create_append_plan(PlannerInfo *root, AppendPath *best_path)
{ {
Append *plan; Append *plan;
List *tlist = build_relation_tlist(best_path->path.parent); List *tlist = build_relation_tlist(best_path->path.parent);
...@@ -463,7 +463,7 @@ create_append_plan(Query *root, AppendPath *best_path) ...@@ -463,7 +463,7 @@ create_append_plan(Query *root, AppendPath *best_path)
* Returns a Plan node. * Returns a Plan node.
*/ */
static Result * static Result *
create_result_plan(Query *root, ResultPath *best_path) create_result_plan(PlannerInfo *root, ResultPath *best_path)
{ {
Result *plan; Result *plan;
List *tlist; List *tlist;
...@@ -495,7 +495,7 @@ create_result_plan(Query *root, ResultPath *best_path) ...@@ -495,7 +495,7 @@ create_result_plan(Query *root, ResultPath *best_path)
* Returns a Plan node. * Returns a Plan node.
*/ */
static Material * static Material *
create_material_plan(Query *root, MaterialPath *best_path) create_material_plan(PlannerInfo *root, MaterialPath *best_path)
{ {
Material *plan; Material *plan;
Plan *subplan; Plan *subplan;
...@@ -520,7 +520,7 @@ create_material_plan(Query *root, MaterialPath *best_path) ...@@ -520,7 +520,7 @@ create_material_plan(Query *root, MaterialPath *best_path)
* Returns a Plan node. * Returns a Plan node.
*/ */
static Plan * static Plan *
create_unique_plan(Query *root, UniquePath *best_path) create_unique_plan(PlannerInfo *root, UniquePath *best_path)
{ {
Plan *plan; Plan *plan;
Plan *subplan; Plan *subplan;
...@@ -535,7 +535,7 @@ create_unique_plan(Query *root, UniquePath *best_path) ...@@ -535,7 +535,7 @@ create_unique_plan(Query *root, UniquePath *best_path)
subplan = create_plan(root, best_path->subpath); subplan = create_plan(root, best_path->subpath);
/* /*----------
* As constructed, the subplan has a "flat" tlist containing just the * As constructed, the subplan has a "flat" tlist containing just the
* Vars needed here and at upper levels. The values we are supposed * Vars needed here and at upper levels. The values we are supposed
* to unique-ify may be expressions in these variables. We have to * to unique-ify may be expressions in these variables. We have to
...@@ -545,19 +545,20 @@ create_unique_plan(Query *root, UniquePath *best_path) ...@@ -545,19 +545,20 @@ create_unique_plan(Query *root, UniquePath *best_path)
* existing subplan outputs, not all the output columns may be used * existing subplan outputs, not all the output columns may be used
* for grouping.) * for grouping.)
* *
* Note: the reason we don't remove any subplan outputs is that there are * Note: the reason we don't remove any subplan outputs is that there
* scenarios where a Var is needed at higher levels even though it is * are scenarios where a Var is needed at higher levels even though
* not one of the nominal outputs of an IN clause. Consider WHERE x * it is not one of the nominal outputs of an IN clause. Consider
* IN (SELECT y FROM t1,t2 WHERE y = z) Implied equality deduction * WHERE x IN (SELECT y FROM t1,t2 WHERE y = z)
* will generate an "x = z" clause, which may get used instead of "x = * Implied equality deduction will generate an "x = z" clause, which may
* y" in the upper join step. Therefore the sub-select had better * get used instead of "x = y" in the upper join step. Therefore the
* deliver both y and z in its targetlist. It is sufficient to * sub-select had better deliver both y and z in its targetlist.
* unique-ify on y, however. * It is sufficient to unique-ify on y, however.
* *
* To find the correct list of values to unique-ify, we look in the * To find the correct list of values to unique-ify, we look in the
* information saved for IN expressions. If this code is ever used in * information saved for IN expressions. If this code is ever used in
* other scenarios, some other way of finding what to unique-ify will * other scenarios, some other way of finding what to unique-ify will
* be needed. * be needed.
*----------
*/ */
uniq_exprs = NIL; /* just to keep compiler quiet */ uniq_exprs = NIL; /* just to keep compiler quiet */
foreach(l, root->in_info_list) foreach(l, root->in_info_list)
...@@ -672,7 +673,7 @@ create_unique_plan(Query *root, UniquePath *best_path) ...@@ -672,7 +673,7 @@ create_unique_plan(Query *root, UniquePath *best_path)
* with restriction clauses 'scan_clauses' and targetlist 'tlist'. * with restriction clauses 'scan_clauses' and targetlist 'tlist'.
*/ */
static SeqScan * static SeqScan *
create_seqscan_plan(Query *root, Path *best_path, create_seqscan_plan(PlannerInfo *root, Path *best_path,
List *tlist, List *scan_clauses) List *tlist, List *scan_clauses)
{ {
SeqScan *scan_plan; SeqScan *scan_plan;
...@@ -710,7 +711,7 @@ create_seqscan_plan(Query *root, Path *best_path, ...@@ -710,7 +711,7 @@ create_seqscan_plan(Query *root, Path *best_path,
* nonlossy indexquals. * nonlossy indexquals.
*/ */
static IndexScan * static IndexScan *
create_indexscan_plan(Query *root, create_indexscan_plan(PlannerInfo *root,
IndexPath *best_path, IndexPath *best_path,
List *tlist, List *tlist,
List *scan_clauses, List *scan_clauses,
...@@ -827,7 +828,7 @@ create_indexscan_plan(Query *root, ...@@ -827,7 +828,7 @@ create_indexscan_plan(Query *root,
* with restriction clauses 'scan_clauses' and targetlist 'tlist'. * with restriction clauses 'scan_clauses' and targetlist 'tlist'.
*/ */
static BitmapHeapScan * static BitmapHeapScan *
create_bitmap_scan_plan(Query *root, create_bitmap_scan_plan(PlannerInfo *root,
BitmapHeapPath *best_path, BitmapHeapPath *best_path,
List *tlist, List *tlist,
List *scan_clauses) List *scan_clauses)
...@@ -925,7 +926,7 @@ create_bitmap_scan_plan(Query *root, ...@@ -925,7 +926,7 @@ create_bitmap_scan_plan(Query *root,
* exclude lossy index operators. * exclude lossy index operators.
*/ */
static Plan * static Plan *
create_bitmap_subplan(Query *root, Path *bitmapqual, create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,
List **qual, List **indexqual) List **qual, List **indexqual)
{ {
Plan *plan; Plan *plan;
...@@ -1029,7 +1030,7 @@ create_bitmap_subplan(Query *root, Path *bitmapqual, ...@@ -1029,7 +1030,7 @@ create_bitmap_subplan(Query *root, Path *bitmapqual,
* with restriction clauses 'scan_clauses' and targetlist 'tlist'. * with restriction clauses 'scan_clauses' and targetlist 'tlist'.
*/ */
static TidScan * static TidScan *
create_tidscan_plan(Query *root, TidPath *best_path, create_tidscan_plan(PlannerInfo *root, TidPath *best_path,
List *tlist, List *scan_clauses) List *tlist, List *scan_clauses)
{ {
TidScan *scan_plan; TidScan *scan_plan;
...@@ -1061,7 +1062,7 @@ create_tidscan_plan(Query *root, TidPath *best_path, ...@@ -1061,7 +1062,7 @@ create_tidscan_plan(Query *root, TidPath *best_path,
* with restriction clauses 'scan_clauses' and targetlist 'tlist'. * with restriction clauses 'scan_clauses' and targetlist 'tlist'.
*/ */
static SubqueryScan * static SubqueryScan *
create_subqueryscan_plan(Query *root, Path *best_path, create_subqueryscan_plan(PlannerInfo *root, Path *best_path,
List *tlist, List *scan_clauses) List *tlist, List *scan_clauses)
{ {
SubqueryScan *scan_plan; SubqueryScan *scan_plan;
...@@ -1093,7 +1094,7 @@ create_subqueryscan_plan(Query *root, Path *best_path, ...@@ -1093,7 +1094,7 @@ create_subqueryscan_plan(Query *root, Path *best_path,
* with restriction clauses 'scan_clauses' and targetlist 'tlist'. * with restriction clauses 'scan_clauses' and targetlist 'tlist'.
*/ */
static FunctionScan * static FunctionScan *
create_functionscan_plan(Query *root, Path *best_path, create_functionscan_plan(PlannerInfo *root, Path *best_path,
List *tlist, List *scan_clauses) List *tlist, List *scan_clauses)
{ {
FunctionScan *scan_plan; FunctionScan *scan_plan;
...@@ -1123,7 +1124,7 @@ create_functionscan_plan(Query *root, Path *best_path, ...@@ -1123,7 +1124,7 @@ create_functionscan_plan(Query *root, Path *best_path,
*****************************************************************************/ *****************************************************************************/
static NestLoop * static NestLoop *
create_nestloop_plan(Query *root, create_nestloop_plan(PlannerInfo *root,
NestPath *best_path, NestPath *best_path,
Plan *outer_plan, Plan *outer_plan,
Plan *inner_plan) Plan *inner_plan)
...@@ -1213,7 +1214,7 @@ create_nestloop_plan(Query *root, ...@@ -1213,7 +1214,7 @@ create_nestloop_plan(Query *root,
} }
static MergeJoin * static MergeJoin *
create_mergejoin_plan(Query *root, create_mergejoin_plan(PlannerInfo *root,
MergePath *best_path, MergePath *best_path,
Plan *outer_plan, Plan *outer_plan,
Plan *inner_plan) Plan *inner_plan)
...@@ -1296,7 +1297,7 @@ create_mergejoin_plan(Query *root, ...@@ -1296,7 +1297,7 @@ create_mergejoin_plan(Query *root,
} }
static HashJoin * static HashJoin *
create_hashjoin_plan(Query *root, create_hashjoin_plan(PlannerInfo *root,
HashPath *best_path, HashPath *best_path,
Plan *outer_plan, Plan *outer_plan,
Plan *inner_plan) Plan *inner_plan)
...@@ -1608,14 +1609,14 @@ get_switched_clauses(List *clauses, Relids outerrelids) ...@@ -1608,14 +1609,14 @@ get_switched_clauses(List *clauses, Relids outerrelids)
* InitPlan references) to the end of the list. * InitPlan references) to the end of the list.
*/ */
List * List *
order_qual_clauses(Query *root, List *clauses) order_qual_clauses(PlannerInfo *root, List *clauses)
{ {
List *nosubplans; List *nosubplans;
List *withsubplans; List *withsubplans;
ListCell *l; ListCell *l;
/* No need to work hard if the query is subselect-free */ /* No need to work hard if the query is subselect-free */
if (!root->hasSubLinks) if (!root->parse->hasSubLinks)
return clauses; return clauses;
nosubplans = NIL; nosubplans = NIL;
...@@ -2018,7 +2019,7 @@ make_mergejoin(List *tlist, ...@@ -2018,7 +2019,7 @@ make_mergejoin(List *tlist,
* Caller must have built the sortColIdx and sortOperators arrays already. * Caller must have built the sortColIdx and sortOperators arrays already.
*/ */
static Sort * static Sort *
make_sort(Query *root, Plan *lefttree, int numCols, make_sort(PlannerInfo *root, Plan *lefttree, int numCols,
AttrNumber *sortColIdx, Oid *sortOperators) AttrNumber *sortColIdx, Oid *sortOperators)
{ {
Sort *node = makeNode(Sort); Sort *node = makeNode(Sort);
...@@ -2090,7 +2091,7 @@ add_sort_column(AttrNumber colIdx, Oid sortOp, ...@@ -2090,7 +2091,7 @@ add_sort_column(AttrNumber colIdx, Oid sortOp,
* adding a Result node just to do the projection. * adding a Result node just to do the projection.
*/ */
static Sort * static Sort *
make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys) make_sort_from_pathkeys(PlannerInfo *root, Plan *lefttree, List *pathkeys)
{ {
List *tlist = lefttree->targetlist; List *tlist = lefttree->targetlist;
ListCell *i; ListCell *i;
...@@ -2201,7 +2202,7 @@ make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys) ...@@ -2201,7 +2202,7 @@ make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys)
* 'lefttree' is the node which yields input tuples * 'lefttree' is the node which yields input tuples
*/ */
Sort * Sort *
make_sort_from_sortclauses(Query *root, List *sortcls, Plan *lefttree) make_sort_from_sortclauses(PlannerInfo *root, List *sortcls, Plan *lefttree)
{ {
List *sub_tlist = lefttree->targetlist; List *sub_tlist = lefttree->targetlist;
ListCell *l; ListCell *l;
...@@ -2253,7 +2254,7 @@ make_sort_from_sortclauses(Query *root, List *sortcls, Plan *lefttree) ...@@ -2253,7 +2254,7 @@ make_sort_from_sortclauses(Query *root, List *sortcls, Plan *lefttree)
* GroupClause entries. * GroupClause entries.
*/ */
Sort * Sort *
make_sort_from_groupcols(Query *root, make_sort_from_groupcols(PlannerInfo *root,
List *groupcls, List *groupcls,
AttrNumber *grpColIdx, AttrNumber *grpColIdx,
Plan *lefttree) Plan *lefttree)
...@@ -2347,7 +2348,7 @@ materialize_finished_plan(Plan *subplan) ...@@ -2347,7 +2348,7 @@ materialize_finished_plan(Plan *subplan)
} }
Agg * Agg *
make_agg(Query *root, List *tlist, List *qual, make_agg(PlannerInfo *root, List *tlist, List *qual,
AggStrategy aggstrategy, AggStrategy aggstrategy,
int numGroupCols, AttrNumber *grpColIdx, int numGroupCols, AttrNumber *grpColIdx,
long numGroups, int numAggs, long numGroups, int numAggs,
...@@ -2412,7 +2413,7 @@ make_agg(Query *root, List *tlist, List *qual, ...@@ -2412,7 +2413,7 @@ make_agg(Query *root, List *tlist, List *qual,
} }
Group * Group *
make_group(Query *root, make_group(PlannerInfo *root,
List *tlist, List *tlist,
List *qual, List *qual,
int numGroupCols, int numGroupCols,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.105 2005/04/28 21:47:13 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.106 2005/06/05 22:32:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,16 +34,16 @@ ...@@ -34,16 +34,16 @@
#include "utils/syscache.h" #include "utils/syscache.h"
static void mark_baserels_for_outer_join(Query *root, Relids rels, static void mark_baserels_for_outer_join(PlannerInfo *root, Relids rels,
Relids outerrels); Relids outerrels);
static void distribute_qual_to_rels(Query *root, Node *clause, static void distribute_qual_to_rels(PlannerInfo *root, Node *clause,
bool is_pushed_down, bool is_pushed_down,
bool isdeduced, bool isdeduced,
Relids outerjoin_nonnullable, Relids outerjoin_nonnullable,
Relids qualscope); Relids qualscope);
static void add_vars_to_targetlist(Query *root, List *vars, static void add_vars_to_targetlist(PlannerInfo *root, List *vars,
Relids where_needed); Relids where_needed);
static bool qual_is_redundant(Query *root, RestrictInfo *restrictinfo, static bool qual_is_redundant(PlannerInfo *root, RestrictInfo *restrictinfo,
List *restrictlist); List *restrictlist);
static void check_mergejoinable(RestrictInfo *restrictinfo); static void check_mergejoinable(RestrictInfo *restrictinfo);
static void check_hashjoinable(RestrictInfo *restrictinfo); static void check_hashjoinable(RestrictInfo *restrictinfo);
...@@ -68,7 +68,7 @@ static void check_hashjoinable(RestrictInfo *restrictinfo); ...@@ -68,7 +68,7 @@ static void check_hashjoinable(RestrictInfo *restrictinfo);
* will be used later to build rels for inheritance children. * will be used later to build rels for inheritance children.
*/ */
void void
add_base_rels_to_query(Query *root, Node *jtnode) add_base_rels_to_query(PlannerInfo *root, Node *jtnode)
{ {
if (jtnode == NULL) if (jtnode == NULL)
return; return;
...@@ -114,7 +114,7 @@ add_base_rels_to_query(Query *root, Node *jtnode) ...@@ -114,7 +114,7 @@ add_base_rels_to_query(Query *root, Node *jtnode)
* propagate up through all join plan steps. * propagate up through all join plan steps.
*/ */
void void
build_base_rel_tlists(Query *root, List *final_tlist) build_base_rel_tlists(PlannerInfo *root, List *final_tlist)
{ {
List *tlist_vars = pull_var_clause((Node *) final_tlist, false); List *tlist_vars = pull_var_clause((Node *) final_tlist, false);
...@@ -133,7 +133,7 @@ build_base_rel_tlists(Query *root, List *final_tlist) ...@@ -133,7 +133,7 @@ build_base_rel_tlists(Query *root, List *final_tlist)
* where_needed includes "relation 0"). * where_needed includes "relation 0").
*/ */
static void static void
add_vars_to_targetlist(Query *root, List *vars, Relids where_needed) add_vars_to_targetlist(PlannerInfo *root, List *vars, Relids where_needed)
{ {
ListCell *temp; ListCell *temp;
...@@ -189,7 +189,7 @@ add_vars_to_targetlist(Query *root, List *vars, Relids where_needed) ...@@ -189,7 +189,7 @@ add_vars_to_targetlist(Query *root, List *vars, Relids where_needed)
* internal convenience; no outside callers pay attention to the result. * internal convenience; no outside callers pay attention to the result.
*/ */
Relids Relids
distribute_quals_to_rels(Query *root, Node *jtnode) distribute_quals_to_rels(PlannerInfo *root, Node *jtnode)
{ {
Relids result = NULL; Relids result = NULL;
...@@ -306,7 +306,7 @@ distribute_quals_to_rels(Query *root, Node *jtnode) ...@@ -306,7 +306,7 @@ distribute_quals_to_rels(Query *root, Node *jtnode)
* Mark all base rels listed in 'rels' as having the given outerjoinset. * Mark all base rels listed in 'rels' as having the given outerjoinset.
*/ */
static void static void
mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels) mark_baserels_for_outer_join(PlannerInfo *root, Relids rels, Relids outerrels)
{ {
Relids tmprelids; Relids tmprelids;
int relno; int relno;
...@@ -333,7 +333,7 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels) ...@@ -333,7 +333,7 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
*/ */
if (rel->outerjoinset == NULL) if (rel->outerjoinset == NULL)
{ {
if (list_member_int(root->rowMarks, relno)) if (list_member_int(root->parse->rowMarks, relno))
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE cannot be applied to the nullable side of an outer join"))); errmsg("SELECT FOR UPDATE/SHARE cannot be applied to the nullable side of an outer join")));
...@@ -367,7 +367,7 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels) ...@@ -367,7 +367,7 @@ mark_baserels_for_outer_join(Query *root, Relids rels, Relids outerrels)
* 'is_pushed_down' will be TRUE. * 'is_pushed_down' will be TRUE.
*/ */
static void static void
distribute_qual_to_rels(Query *root, Node *clause, distribute_qual_to_rels(PlannerInfo *root, Node *clause,
bool is_pushed_down, bool is_pushed_down,
bool isdeduced, bool isdeduced,
Relids outerjoin_nonnullable, Relids outerjoin_nonnullable,
...@@ -626,7 +626,7 @@ distribute_qual_to_rels(Query *root, Node *clause, ...@@ -626,7 +626,7 @@ distribute_qual_to_rels(Query *root, Node *clause,
* for more details. * for more details.
*/ */
void void
process_implied_equality(Query *root, process_implied_equality(PlannerInfo *root,
Node *item1, Node *item2, Node *item1, Node *item2,
Oid sortop1, Oid sortop2, Oid sortop1, Oid sortop2,
Relids item1_relids, Relids item2_relids, Relids item1_relids, Relids item2_relids,
...@@ -796,7 +796,7 @@ process_implied_equality(Query *root, ...@@ -796,7 +796,7 @@ process_implied_equality(Query *root,
* all the "var = const" quals. * all the "var = const" quals.
*/ */
static bool static bool
qual_is_redundant(Query *root, qual_is_redundant(PlannerInfo *root,
RestrictInfo *restrictinfo, RestrictInfo *restrictinfo,
List *restrictlist) List *restrictlist)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.4 2005/04/22 21:58:31 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.5 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -42,11 +42,11 @@ typedef struct ...@@ -42,11 +42,11 @@ typedef struct
} MinMaxAggInfo; } MinMaxAggInfo;
static bool find_minmax_aggs_walker(Node *node, List **context); static bool find_minmax_aggs_walker(Node *node, List **context);
static bool build_minmax_path(Query *root, RelOptInfo *rel, static bool build_minmax_path(PlannerInfo *root, RelOptInfo *rel,
MinMaxAggInfo *info); MinMaxAggInfo *info);
static ScanDirection match_agg_to_index_col(MinMaxAggInfo *info, static ScanDirection match_agg_to_index_col(MinMaxAggInfo *info,
IndexOptInfo *index, int indexcol); IndexOptInfo *index, int indexcol);
static void make_agg_subplan(Query *root, MinMaxAggInfo *info, static void make_agg_subplan(PlannerInfo *root, MinMaxAggInfo *info,
List *constant_quals); List *constant_quals);
static Node *replace_aggs_with_params_mutator(Node *node, List **context); static Node *replace_aggs_with_params_mutator(Node *node, List **context);
static Oid fetch_agg_sort_op(Oid aggfnoid); static Oid fetch_agg_sort_op(Oid aggfnoid);
...@@ -61,15 +61,16 @@ static Oid fetch_agg_sort_op(Oid aggfnoid); ...@@ -61,15 +61,16 @@ static Oid fetch_agg_sort_op(Oid aggfnoid);
* Given a suitable index on tab.col, this can be much faster than the * Given a suitable index on tab.col, this can be much faster than the
* generic scan-all-the-rows plan. * generic scan-all-the-rows plan.
* *
* We are passed the Query, the preprocessed tlist, and the best path * We are passed the preprocessed tlist, and the best path
* devised for computing the input of a standard Agg node. If we are able * devised for computing the input of a standard Agg node. If we are able
* to optimize all the aggregates, and the result is estimated to be cheaper * to optimize all the aggregates, and the result is estimated to be cheaper
* than the generic aggregate method, then generate and return a Plan that * than the generic aggregate method, then generate and return a Plan that
* does it that way. Otherwise, return NULL. * does it that way. Otherwise, return NULL.
*/ */
Plan * Plan *
optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path) optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
{ {
Query *parse = root->parse;
RangeTblRef *rtr; RangeTblRef *rtr;
RangeTblEntry *rte; RangeTblEntry *rte;
RelOptInfo *rel; RelOptInfo *rel;
...@@ -83,11 +84,11 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path) ...@@ -83,11 +84,11 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path)
List *constant_quals; List *constant_quals;
/* Nothing to do if query has no aggregates */ /* Nothing to do if query has no aggregates */
if (!root->hasAggs) if (!parse->hasAggs)
return NULL; return NULL;
Assert(!root->setOperations); /* shouldn't get here if a setop */ Assert(!parse->setOperations); /* shouldn't get here if a setop */
Assert(root->rowMarks == NIL); /* nor if FOR UPDATE */ Assert(parse->rowMarks == NIL); /* nor if FOR UPDATE */
/* /*
* Reject unoptimizable cases. * Reject unoptimizable cases.
...@@ -96,7 +97,7 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path) ...@@ -96,7 +97,7 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path)
* grouping require looking at all the rows anyway, and so there's not * grouping require looking at all the rows anyway, and so there's not
* much point in optimizing MIN/MAX. * much point in optimizing MIN/MAX.
*/ */
if (root->groupClause) if (parse->groupClause)
return NULL; return NULL;
/* /*
...@@ -105,13 +106,13 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path) ...@@ -105,13 +106,13 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path)
* handle a query containing cartesian-product joins, but it hardly * handle a query containing cartesian-product joins, but it hardly
* seems worth the trouble.) * seems worth the trouble.)
*/ */
Assert(root->jointree != NULL && IsA(root->jointree, FromExpr)); Assert(parse->jointree != NULL && IsA(parse->jointree, FromExpr));
if (list_length(root->jointree->fromlist) != 1) if (list_length(parse->jointree->fromlist) != 1)
return NULL; return NULL;
rtr = (RangeTblRef *) linitial(root->jointree->fromlist); rtr = (RangeTblRef *) linitial(parse->jointree->fromlist);
if (!IsA(rtr, RangeTblRef)) if (!IsA(rtr, RangeTblRef))
return NULL; return NULL;
rte = rt_fetch(rtr->rtindex, root->rtable); rte = rt_fetch(rtr->rtindex, parse->rtable);
if (rte->rtekind != RTE_RELATION) if (rte->rtekind != RTE_RELATION)
return NULL; return NULL;
rel = find_base_rel(root, rtr->rtindex); rel = find_base_rel(root, rtr->rtindex);
...@@ -121,8 +122,8 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path) ...@@ -121,8 +122,8 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path)
* This may be overly paranoid, but it's not entirely clear if the * This may be overly paranoid, but it's not entirely clear if the
* transformation is safe then. * transformation is safe then.
*/ */
if (contain_subplans(root->jointree->quals) || if (contain_subplans(parse->jointree->quals) ||
contain_volatile_functions(root->jointree->quals)) contain_volatile_functions(parse->jointree->quals))
return NULL; return NULL;
/* /*
...@@ -143,7 +144,7 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path) ...@@ -143,7 +144,7 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path)
aggs_list = NIL; aggs_list = NIL;
if (find_minmax_aggs_walker((Node *) tlist, &aggs_list)) if (find_minmax_aggs_walker((Node *) tlist, &aggs_list))
return NULL; return NULL;
if (find_minmax_aggs_walker(root->havingQual, &aggs_list)) if (find_minmax_aggs_walker(parse->havingQual, &aggs_list))
return NULL; return NULL;
/* Pass 2: see if each one is optimizable */ /* Pass 2: see if each one is optimizable */
...@@ -202,7 +203,7 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path) ...@@ -202,7 +203,7 @@ optimize_minmax_aggregates(Query *root, List *tlist, Path *best_path)
*/ */
tlist = (List *) replace_aggs_with_params_mutator((Node *) tlist, tlist = (List *) replace_aggs_with_params_mutator((Node *) tlist,
&aggs_list); &aggs_list);
hqual = replace_aggs_with_params_mutator(root->havingQual, hqual = replace_aggs_with_params_mutator(parse->havingQual,
&aggs_list); &aggs_list);
/* /*
...@@ -298,7 +299,7 @@ find_minmax_aggs_walker(Node *node, List **context) ...@@ -298,7 +299,7 @@ find_minmax_aggs_walker(Node *node, List **context)
* Note: check_partial_indexes() must have been run previously. * Note: check_partial_indexes() must have been run previously.
*/ */
static bool static bool
build_minmax_path(Query *root, RelOptInfo *rel, MinMaxAggInfo *info) build_minmax_path(PlannerInfo *root, RelOptInfo *rel, MinMaxAggInfo *info)
{ {
IndexPath *best_path = NULL; IndexPath *best_path = NULL;
Cost best_cost = 0; Cost best_cost = 0;
...@@ -441,46 +442,48 @@ match_agg_to_index_col(MinMaxAggInfo *info, IndexOptInfo *index, int indexcol) ...@@ -441,46 +442,48 @@ match_agg_to_index_col(MinMaxAggInfo *info, IndexOptInfo *index, int indexcol)
* Construct a suitable plan for a converted aggregate query * Construct a suitable plan for a converted aggregate query
*/ */
static void static void
make_agg_subplan(Query *root, MinMaxAggInfo *info, List *constant_quals) make_agg_subplan(PlannerInfo *root, MinMaxAggInfo *info, List *constant_quals)
{ {
Query *subquery; PlannerInfo subroot;
Query *subparse;
Plan *plan; Plan *plan;
TargetEntry *tle; TargetEntry *tle;
SortClause *sortcl; SortClause *sortcl;
NullTest *ntest; NullTest *ntest;
/* /*
* Generate a suitably modified Query node. Much of the work here is * Generate a suitably modified query. Much of the work here is
* probably unnecessary in the normal case, but we want to make it look * probably unnecessary in the normal case, but we want to make it look
* good if someone tries to EXPLAIN the result. * good if someone tries to EXPLAIN the result.
*/ */
subquery = (Query *) copyObject(root); memcpy(&subroot, root, sizeof(PlannerInfo));
subquery->commandType = CMD_SELECT; subroot.parse = subparse = (Query *) copyObject(root->parse);
subquery->resultRelation = 0; subparse->commandType = CMD_SELECT;
subquery->resultRelations = NIL; subparse->resultRelation = 0;
subquery->into = NULL; subparse->resultRelations = NIL;
subquery->hasAggs = false; subparse->into = NULL;
subquery->groupClause = NIL; subparse->hasAggs = false;
subquery->havingQual = NULL; subparse->groupClause = NIL;
subquery->hasHavingQual = false; subparse->havingQual = NULL;
subquery->distinctClause = NIL; subparse->distinctClause = NIL;
subroot.hasHavingQual = false;
/* single tlist entry that is the aggregate target */ /* single tlist entry that is the aggregate target */
tle = makeTargetEntry(copyObject(info->target), tle = makeTargetEntry(copyObject(info->target),
1, 1,
pstrdup("agg_target"), pstrdup("agg_target"),
false); false);
subquery->targetList = list_make1(tle); subparse->targetList = list_make1(tle);
/* set up the appropriate ORDER BY entry */ /* set up the appropriate ORDER BY entry */
sortcl = makeNode(SortClause); sortcl = makeNode(SortClause);
sortcl->tleSortGroupRef = assignSortGroupRef(tle, subquery->targetList); sortcl->tleSortGroupRef = assignSortGroupRef(tle, subparse->targetList);
sortcl->sortop = info->aggsortop; sortcl->sortop = info->aggsortop;
subquery->sortClause = list_make1(sortcl); subparse->sortClause = list_make1(sortcl);
/* set up LIMIT 1 */ /* set up LIMIT 1 */
subquery->limitOffset = NULL; subparse->limitOffset = NULL;
subquery->limitCount = (Node *) makeConst(INT4OID, sizeof(int4), subparse->limitCount = (Node *) makeConst(INT4OID, sizeof(int4),
Int32GetDatum(1), Int32GetDatum(1),
false, true); false, true);
...@@ -498,9 +501,9 @@ make_agg_subplan(Query *root, MinMaxAggInfo *info, List *constant_quals) ...@@ -498,9 +501,9 @@ make_agg_subplan(Query *root, MinMaxAggInfo *info, List *constant_quals)
* most cases the fraction of NULLs isn't high enough to change the * most cases the fraction of NULLs isn't high enough to change the
* decision. * decision.
*/ */
plan = create_plan(subquery, (Path *) info->path); plan = create_plan(&subroot, (Path *) info->path);
plan->targetlist = copyObject(subquery->targetList); plan->targetlist = copyObject(subparse->targetList);
ntest = makeNode(NullTest); ntest = makeNode(NullTest);
ntest->nulltesttype = IS_NOT_NULL; ntest->nulltesttype = IS_NOT_NULL;
...@@ -514,13 +517,13 @@ make_agg_subplan(Query *root, MinMaxAggInfo *info, List *constant_quals) ...@@ -514,13 +517,13 @@ make_agg_subplan(Query *root, MinMaxAggInfo *info, List *constant_quals)
plan); plan);
plan = (Plan *) make_limit(plan, plan = (Plan *) make_limit(plan,
subquery->limitOffset, subparse->limitOffset,
subquery->limitCount); subparse->limitCount);
/* /*
* Convert the plan into an InitPlan, and make a Param for its result. * Convert the plan into an InitPlan, and make a Param for its result.
*/ */
info->param = SS_make_initplan_from_plan(subquery, plan, info->param = SS_make_initplan_from_plan(&subroot, plan,
exprType((Node *) tle->expr), exprType((Node *) tle->expr),
-1); -1);
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.81 2004/12/31 22:00:09 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.82 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -42,8 +42,9 @@ ...@@ -42,8 +42,9 @@
* will make the final decision about which to use. * will make the final decision about which to use.
* *
* Input parameters: * Input parameters:
* root is the query to plan * root describes the query to plan
* tlist is the target list the query should produce (NOT root->targetList!) * tlist is the target list the query should produce
* (this is NOT necessarily root->parse->targetList!)
* tuple_fraction is the fraction of tuples we expect will be retrieved * tuple_fraction is the fraction of tuples we expect will be retrieved
* *
* Output parameters: * Output parameters:
...@@ -51,14 +52,14 @@ ...@@ -51,14 +52,14 @@
* *sorted_path receives the cheapest presorted path for the query, * *sorted_path receives the cheapest presorted path for the query,
* if any (NULL if there is no useful presorted path) * if any (NULL if there is no useful presorted path)
* *
* Note: the Query node also includes a query_pathkeys field, which is both * Note: the PlannerInfo node also includes a query_pathkeys field, which is
* an input and an output of query_planner(). The input value signals * both an input and an output of query_planner(). The input value signals
* query_planner that the indicated sort order is wanted in the final output * query_planner that the indicated sort order is wanted in the final output
* plan. But this value has not yet been "canonicalized", since the needed * plan. But this value has not yet been "canonicalized", since the needed
* info does not get computed until we scan the qual clauses. We canonicalize * info does not get computed until we scan the qual clauses. We canonicalize
* it as soon as that task is done. (The main reason query_pathkeys is a * it as soon as that task is done. (The main reason query_pathkeys is a
* Query field and not a passed parameter is that the low-level routines in * PlannerInfo field and not a passed parameter is that the low-level routines
* indxpath.c need to see it.) * in indxpath.c need to see it.)
* *
* tuple_fraction is interpreted as follows: * tuple_fraction is interpreted as follows:
* 0: expect all tuples to be retrieved (normal case) * 0: expect all tuples to be retrieved (normal case)
...@@ -69,9 +70,10 @@ ...@@ -69,9 +70,10 @@
*-------------------- *--------------------
*/ */
void void
query_planner(Query *root, List *tlist, double tuple_fraction, query_planner(PlannerInfo *root, List *tlist, double tuple_fraction,
Path **cheapest_path, Path **sorted_path) Path **cheapest_path, Path **sorted_path)
{ {
Query *parse = root->parse;
List *constant_quals; List *constant_quals;
RelOptInfo *final_rel; RelOptInfo *final_rel;
Path *cheapestpath; Path *cheapestpath;
...@@ -81,10 +83,10 @@ query_planner(Query *root, List *tlist, double tuple_fraction, ...@@ -81,10 +83,10 @@ query_planner(Query *root, List *tlist, double tuple_fraction,
* If the query has an empty join tree, then it's something easy like * If the query has an empty join tree, then it's something easy like
* "SELECT 2+2;" or "INSERT ... VALUES()". Fall through quickly. * "SELECT 2+2;" or "INSERT ... VALUES()". Fall through quickly.
*/ */
if (root->jointree->fromlist == NIL) if (parse->jointree->fromlist == NIL)
{ {
*cheapest_path = (Path *) create_result_path(NULL, NULL, *cheapest_path = (Path *) create_result_path(NULL, NULL,
(List *) root->jointree->quals); (List *) parse->jointree->quals);
*sorted_path = NULL; *sorted_path = NULL;
return; return;
} }
...@@ -99,8 +101,8 @@ query_planner(Query *root, List *tlist, double tuple_fraction, ...@@ -99,8 +101,8 @@ query_planner(Query *root, List *tlist, double tuple_fraction,
* vars, although if the qual reduces to "WHERE FALSE" this path will * vars, although if the qual reduces to "WHERE FALSE" this path will
* also be taken. * also be taken.
*/ */
root->jointree->quals = (Node *) parse->jointree->quals = (Node *)
pull_constant_clauses((List *) root->jointree->quals, pull_constant_clauses((List *) parse->jointree->quals,
&constant_quals); &constant_quals);
/* /*
...@@ -116,7 +118,7 @@ query_planner(Query *root, List *tlist, double tuple_fraction, ...@@ -116,7 +118,7 @@ query_planner(Query *root, List *tlist, double tuple_fraction,
/* /*
* Construct RelOptInfo nodes for all base relations in query. * Construct RelOptInfo nodes for all base relations in query.
*/ */
add_base_rels_to_query(root, (Node *) root->jointree); add_base_rels_to_query(root, (Node *) parse->jointree);
/* /*
* Examine the targetlist and qualifications, adding entries to * Examine the targetlist and qualifications, adding entries to
...@@ -133,7 +135,7 @@ query_planner(Query *root, List *tlist, double tuple_fraction, ...@@ -133,7 +135,7 @@ query_planner(Query *root, List *tlist, double tuple_fraction,
*/ */
build_base_rel_tlists(root, tlist); build_base_rel_tlists(root, tlist);
(void) distribute_quals_to_rels(root, (Node *) root->jointree); (void) distribute_quals_to_rels(root, (Node *) parse->jointree);
/* /*
* Use the completed lists of equijoined keys to deduce any implied * Use the completed lists of equijoined keys to deduce any implied
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.187 2005/05/30 01:04:44 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.188 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -54,18 +54,18 @@ ParamListInfo PlannerBoundParamList = NULL; /* current boundParams */ ...@@ -54,18 +54,18 @@ ParamListInfo PlannerBoundParamList = NULL; /* current boundParams */
#define EXPRKIND_ININFO 4 #define EXPRKIND_ININFO 4
static Node *preprocess_expression(Query *parse, Node *expr, int kind); static Node *preprocess_expression(PlannerInfo *root, Node *expr, int kind);
static void preprocess_qual_conditions(Query *parse, Node *jtnode); static void preprocess_qual_conditions(PlannerInfo *root, Node *jtnode);
static Plan *inheritance_planner(Query *parse, List *inheritlist); static Plan *inheritance_planner(PlannerInfo *root, List *inheritlist);
static Plan *grouping_planner(Query *parse, double tuple_fraction); static Plan *grouping_planner(PlannerInfo *root, double tuple_fraction);
static bool choose_hashed_grouping(Query *parse, double tuple_fraction, static bool choose_hashed_grouping(PlannerInfo *root, double tuple_fraction,
Path *cheapest_path, Path *sorted_path, Path *cheapest_path, Path *sorted_path,
List *sort_pathkeys, List *group_pathkeys, List *sort_pathkeys, List *group_pathkeys,
double dNumGroups, AggClauseCounts *agg_counts); double dNumGroups, AggClauseCounts *agg_counts);
static bool hash_safe_grouping(Query *parse); static bool hash_safe_grouping(PlannerInfo *root);
static List *make_subplanTargetList(Query *parse, List *tlist, static List *make_subplanTargetList(PlannerInfo *root, List *tlist,
AttrNumber **groupColIdx, bool *need_tlist_eval); AttrNumber **groupColIdx, bool *need_tlist_eval);
static void locate_grouping_columns(Query *parse, static void locate_grouping_columns(PlannerInfo *root,
List *tlist, List *tlist,
List *sub_tlist, List *sub_tlist,
AttrNumber *groupColIdx); AttrNumber *groupColIdx);
...@@ -92,10 +92,10 @@ planner(Query *parse, bool isCursor, int cursorOptions, ...@@ -92,10 +92,10 @@ planner(Query *parse, bool isCursor, int cursorOptions,
* eval_const_expressions tries to pre-evaluate an SQL function). So, * eval_const_expressions tries to pre-evaluate an SQL function). So,
* these global state variables must be saved and restored. * these global state variables must be saved and restored.
* *
* Query level and the param list cannot be moved into the Query * Query level and the param list cannot be moved into the per-query
* structure since their whole purpose is communication across * PlannerInfo structure since their whole purpose is communication
* multiple sub-Queries. Also, boundParams is explicitly info from * across multiple sub-queries. Also, boundParams is explicitly info
* outside the Query, and so is likewise better handled as a global * from outside the query, and so is likewise better handled as a global
* variable. * variable.
* *
* Note we do NOT save and restore PlannerPlanId: it exists to assign * Note we do NOT save and restore PlannerPlanId: it exists to assign
...@@ -130,8 +130,9 @@ planner(Query *parse, bool isCursor, int cursorOptions, ...@@ -130,8 +130,9 @@ planner(Query *parse, bool isCursor, int cursorOptions,
} }
/* primary planning entry point (may recurse for subqueries) */ /* primary planning entry point (may recurse for subqueries) */
result_plan = subquery_planner(parse, tuple_fraction); result_plan = subquery_planner(parse, tuple_fraction, NULL);
/* check we popped out the right number of levels */
Assert(PlannerQueryLevel == 0); Assert(PlannerQueryLevel == 0);
/* /*
...@@ -168,6 +169,9 @@ planner(Query *parse, bool isCursor, int cursorOptions, ...@@ -168,6 +169,9 @@ planner(Query *parse, bool isCursor, int cursorOptions,
* tuple_fraction is the fraction of tuples we expect will be retrieved. * tuple_fraction is the fraction of tuples we expect will be retrieved.
* tuple_fraction is interpreted as explained for grouping_planner, below. * tuple_fraction is interpreted as explained for grouping_planner, below.
* *
* If subquery_pathkeys isn't NULL, it receives a list of pathkeys indicating
* the output sort ordering of the completed plan.
*
* Basically, this routine does the stuff that should only be done once * Basically, this routine does the stuff that should only be done once
* per Query object. It then calls grouping_planner. At one time, * per Query object. It then calls grouping_planner. At one time,
* grouping_planner could be invoked recursively on the same Query object; * grouping_planner could be invoked recursively on the same Query object;
...@@ -181,12 +185,14 @@ planner(Query *parse, bool isCursor, int cursorOptions, ...@@ -181,12 +185,14 @@ planner(Query *parse, bool isCursor, int cursorOptions,
*-------------------- *--------------------
*/ */
Plan * Plan *
subquery_planner(Query *parse, double tuple_fraction) subquery_planner(Query *parse, double tuple_fraction,
List **subquery_pathkeys)
{ {
List *saved_initplan = PlannerInitPlan; List *saved_initplan = PlannerInitPlan;
int saved_planid = PlannerPlanId; int saved_planid = PlannerPlanId;
bool hasOuterJoins; PlannerInfo *root;
Plan *plan; Plan *plan;
bool hasOuterJoins;
List *newHaving; List *newHaving;
List *lst; List *lst;
ListCell *l; ListCell *l;
...@@ -195,23 +201,27 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -195,23 +201,27 @@ subquery_planner(Query *parse, double tuple_fraction)
PlannerQueryLevel++; PlannerQueryLevel++;
PlannerInitPlan = NIL; PlannerInitPlan = NIL;
/* Create a PlannerInfo data structure for this subquery */
root = makeNode(PlannerInfo);
root->parse = parse;
/* /*
* Look for IN clauses at the top level of WHERE, and transform them * Look for IN clauses at the top level of WHERE, and transform them
* into joins. Note that this step only handles IN clauses originally * into joins. Note that this step only handles IN clauses originally
* at top level of WHERE; if we pull up any subqueries in the next * at top level of WHERE; if we pull up any subqueries in the next
* step, their INs are processed just before pulling them up. * step, their INs are processed just before pulling them up.
*/ */
parse->in_info_list = NIL; root->in_info_list = NIL;
if (parse->hasSubLinks) if (parse->hasSubLinks)
parse->jointree->quals = pull_up_IN_clauses(parse, parse->jointree->quals = pull_up_IN_clauses(root,
parse->jointree->quals); parse->jointree->quals);
/* /*
* Check to see if any subqueries in the rangetable can be merged into * Check to see if any subqueries in the rangetable can be merged into
* this query. * this query.
*/ */
parse->jointree = (FromExpr *) parse->jointree = (FromExpr *)
pull_up_subqueries(parse, (Node *) parse->jointree, false); pull_up_subqueries(root, (Node *) parse->jointree, false);
/* /*
* Detect whether any rangetable entries are RTE_JOIN kind; if not, we * Detect whether any rangetable entries are RTE_JOIN kind; if not, we
...@@ -220,7 +230,7 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -220,7 +230,7 @@ subquery_planner(Query *parse, double tuple_fraction)
* reduce_outer_joins(). This must be done after we have done * reduce_outer_joins(). This must be done after we have done
* pull_up_subqueries, of course. * pull_up_subqueries, of course.
*/ */
parse->hasJoinRTEs = false; root->hasJoinRTEs = false;
hasOuterJoins = false; hasOuterJoins = false;
foreach(l, parse->rtable) foreach(l, parse->rtable)
{ {
...@@ -228,7 +238,7 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -228,7 +238,7 @@ subquery_planner(Query *parse, double tuple_fraction)
if (rte->rtekind == RTE_JOIN) if (rte->rtekind == RTE_JOIN)
{ {
parse->hasJoinRTEs = true; root->hasJoinRTEs = true;
if (IS_OUTER_JOIN(rte->jointype)) if (IS_OUTER_JOIN(rte->jointype))
{ {
hasOuterJoins = true; hasOuterJoins = true;
...@@ -243,27 +253,27 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -243,27 +253,27 @@ subquery_planner(Query *parse, double tuple_fraction)
* because preprocess_expression will reduce a constant-true condition * because preprocess_expression will reduce a constant-true condition
* to an empty qual list ... but "HAVING TRUE" is not a semantic no-op. * to an empty qual list ... but "HAVING TRUE" is not a semantic no-op.
*/ */
parse->hasHavingQual = (parse->havingQual != NULL); root->hasHavingQual = (parse->havingQual != NULL);
/* /*
* Do expression preprocessing on targetlist and quals. * Do expression preprocessing on targetlist and quals.
*/ */
parse->targetList = (List *) parse->targetList = (List *)
preprocess_expression(parse, (Node *) parse->targetList, preprocess_expression(root, (Node *) parse->targetList,
EXPRKIND_TARGET); EXPRKIND_TARGET);
preprocess_qual_conditions(parse, (Node *) parse->jointree); preprocess_qual_conditions(root, (Node *) parse->jointree);
parse->havingQual = preprocess_expression(parse, parse->havingQual, parse->havingQual = preprocess_expression(root, parse->havingQual,
EXPRKIND_QUAL); EXPRKIND_QUAL);
parse->limitOffset = preprocess_expression(parse, parse->limitOffset, parse->limitOffset = preprocess_expression(root, parse->limitOffset,
EXPRKIND_LIMIT); EXPRKIND_LIMIT);
parse->limitCount = preprocess_expression(parse, parse->limitCount, parse->limitCount = preprocess_expression(root, parse->limitCount,
EXPRKIND_LIMIT); EXPRKIND_LIMIT);
parse->in_info_list = (List *) root->in_info_list = (List *)
preprocess_expression(parse, (Node *) parse->in_info_list, preprocess_expression(root, (Node *) root->in_info_list,
EXPRKIND_ININFO); EXPRKIND_ININFO);
/* Also need to preprocess expressions for function RTEs */ /* Also need to preprocess expressions for function RTEs */
...@@ -272,7 +282,7 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -272,7 +282,7 @@ subquery_planner(Query *parse, double tuple_fraction)
RangeTblEntry *rte = (RangeTblEntry *) lfirst(l); RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
if (rte->rtekind == RTE_FUNCTION) if (rte->rtekind == RTE_FUNCTION)
rte->funcexpr = preprocess_expression(parse, rte->funcexpr, rte->funcexpr = preprocess_expression(root, rte->funcexpr,
EXPRKIND_RTFUNC); EXPRKIND_RTFUNC);
} }
...@@ -336,7 +346,7 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -336,7 +346,7 @@ subquery_planner(Query *parse, double tuple_fraction)
* preprocessing. * preprocessing.
*/ */
if (hasOuterJoins) if (hasOuterJoins)
reduce_outer_joins(parse); reduce_outer_joins(root);
/* /*
* See if we can simplify the jointree; opportunities for this may * See if we can simplify the jointree; opportunities for this may
...@@ -347,7 +357,7 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -347,7 +357,7 @@ subquery_planner(Query *parse, double tuple_fraction)
* after reduce_outer_joins, anyway. * after reduce_outer_joins, anyway.
*/ */
parse->jointree = (FromExpr *) parse->jointree = (FromExpr *)
simplify_jointree(parse, (Node *) parse->jointree); simplify_jointree(root, (Node *) parse->jointree);
/* /*
* Do the main planning. If we have an inherited target relation, * Do the main planning. If we have an inherited target relation,
...@@ -355,10 +365,10 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -355,10 +365,10 @@ subquery_planner(Query *parse, double tuple_fraction)
* grouping_planner. * grouping_planner.
*/ */
if (parse->resultRelation && if (parse->resultRelation &&
(lst = expand_inherited_rtentry(parse, parse->resultRelation)) != NIL) (lst = expand_inherited_rtentry(root, parse->resultRelation)) != NIL)
plan = inheritance_planner(parse, lst); plan = inheritance_planner(root, lst);
else else
plan = grouping_planner(parse, tuple_fraction); plan = grouping_planner(root, tuple_fraction);
/* /*
* If any subplans were generated, or if we're inside a subplan, build * If any subplans were generated, or if we're inside a subplan, build
...@@ -368,6 +378,10 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -368,6 +378,10 @@ subquery_planner(Query *parse, double tuple_fraction)
if (PlannerPlanId != saved_planid || PlannerQueryLevel > 1) if (PlannerPlanId != saved_planid || PlannerQueryLevel > 1)
SS_finalize_plan(plan, parse->rtable); SS_finalize_plan(plan, parse->rtable);
/* Return sort ordering info if caller wants it */
if (subquery_pathkeys)
*subquery_pathkeys = root->query_pathkeys;
/* Return to outer subquery context */ /* Return to outer subquery context */
PlannerQueryLevel--; PlannerQueryLevel--;
PlannerInitPlan = saved_initplan; PlannerInitPlan = saved_initplan;
...@@ -383,7 +397,7 @@ subquery_planner(Query *parse, double tuple_fraction) ...@@ -383,7 +397,7 @@ subquery_planner(Query *parse, double tuple_fraction)
* conditions), or a HAVING clause. * conditions), or a HAVING clause.
*/ */
static Node * static Node *
preprocess_expression(Query *parse, Node *expr, int kind) preprocess_expression(PlannerInfo *root, Node *expr, int kind)
{ {
/* /*
* Fall out quickly if expression is empty. This occurs often enough * Fall out quickly if expression is empty. This occurs often enough
...@@ -399,8 +413,8 @@ preprocess_expression(Query *parse, Node *expr, int kind) ...@@ -399,8 +413,8 @@ preprocess_expression(Query *parse, Node *expr, int kind)
* else sublinks expanded out from join aliases wouldn't get * else sublinks expanded out from join aliases wouldn't get
* processed. * processed.
*/ */
if (parse->hasJoinRTEs) if (root->hasJoinRTEs)
expr = flatten_join_alias_vars(parse, expr); expr = flatten_join_alias_vars(root, expr);
/* /*
* Simplify constant expressions. * Simplify constant expressions.
...@@ -418,7 +432,7 @@ preprocess_expression(Query *parse, Node *expr, int kind) ...@@ -418,7 +432,7 @@ preprocess_expression(Query *parse, Node *expr, int kind)
* still must do it for quals (to get AND/OR flatness); and if we are * still must do it for quals (to get AND/OR flatness); and if we are
* in a subquery we should not assume it will be done only once. * in a subquery we should not assume it will be done only once.
*/ */
if (parse->jointree->fromlist != NIL || if (root->parse->jointree->fromlist != NIL ||
kind == EXPRKIND_QUAL || kind == EXPRKIND_QUAL ||
PlannerQueryLevel > 1) PlannerQueryLevel > 1)
expr = eval_const_expressions(expr); expr = eval_const_expressions(expr);
...@@ -437,7 +451,7 @@ preprocess_expression(Query *parse, Node *expr, int kind) ...@@ -437,7 +451,7 @@ preprocess_expression(Query *parse, Node *expr, int kind)
} }
/* Expand SubLinks to SubPlans */ /* Expand SubLinks to SubPlans */
if (parse->hasSubLinks) if (root->parse->hasSubLinks)
expr = SS_process_sublinks(expr, (kind == EXPRKIND_QUAL)); expr = SS_process_sublinks(expr, (kind == EXPRKIND_QUAL));
/* /*
...@@ -467,7 +481,7 @@ preprocess_expression(Query *parse, Node *expr, int kind) ...@@ -467,7 +481,7 @@ preprocess_expression(Query *parse, Node *expr, int kind)
* preprocessing work on each qual condition found therein. * preprocessing work on each qual condition found therein.
*/ */
static void static void
preprocess_qual_conditions(Query *parse, Node *jtnode) preprocess_qual_conditions(PlannerInfo *root, Node *jtnode)
{ {
if (jtnode == NULL) if (jtnode == NULL)
return; return;
...@@ -481,18 +495,18 @@ preprocess_qual_conditions(Query *parse, Node *jtnode) ...@@ -481,18 +495,18 @@ preprocess_qual_conditions(Query *parse, Node *jtnode)
ListCell *l; ListCell *l;
foreach(l, f->fromlist) foreach(l, f->fromlist)
preprocess_qual_conditions(parse, lfirst(l)); preprocess_qual_conditions(root, lfirst(l));
f->quals = preprocess_expression(parse, f->quals, EXPRKIND_QUAL); f->quals = preprocess_expression(root, f->quals, EXPRKIND_QUAL);
} }
else if (IsA(jtnode, JoinExpr)) else if (IsA(jtnode, JoinExpr))
{ {
JoinExpr *j = (JoinExpr *) jtnode; JoinExpr *j = (JoinExpr *) jtnode;
preprocess_qual_conditions(parse, j->larg); preprocess_qual_conditions(root, j->larg);
preprocess_qual_conditions(parse, j->rarg); preprocess_qual_conditions(root, j->rarg);
j->quals = preprocess_expression(parse, j->quals, EXPRKIND_QUAL); j->quals = preprocess_expression(root, j->quals, EXPRKIND_QUAL);
} }
else else
elog(ERROR, "unrecognized node type: %d", elog(ERROR, "unrecognized node type: %d",
...@@ -514,15 +528,15 @@ preprocess_qual_conditions(Query *parse, Node *jtnode) ...@@ -514,15 +528,15 @@ preprocess_qual_conditions(Query *parse, Node *jtnode)
* can never be the nullable side of an outer join, so it's OK to generate * can never be the nullable side of an outer join, so it's OK to generate
* the plan this way. * the plan this way.
* *
* parse is the querytree produced by the parser & rewriter.
* inheritlist is an integer list of RT indexes for the result relation set. * inheritlist is an integer list of RT indexes for the result relation set.
* *
* Returns a query plan. * Returns a query plan.
*-------------------- *--------------------
*/ */
static Plan * static Plan *
inheritance_planner(Query *parse, List *inheritlist) inheritance_planner(PlannerInfo *root, List *inheritlist)
{ {
Query *parse = root->parse;
int parentRTindex = parse->resultRelation; int parentRTindex = parse->resultRelation;
Oid parentOID = getrelid(parentRTindex, parse->rtable); Oid parentOID = getrelid(parentRTindex, parse->rtable);
int mainrtlength = list_length(parse->rtable); int mainrtlength = list_length(parse->rtable);
...@@ -534,15 +548,27 @@ inheritance_planner(Query *parse, List *inheritlist) ...@@ -534,15 +548,27 @@ inheritance_planner(Query *parse, List *inheritlist)
{ {
int childRTindex = lfirst_int(l); int childRTindex = lfirst_int(l);
Oid childOID = getrelid(childRTindex, parse->rtable); Oid childOID = getrelid(childRTindex, parse->rtable);
Query *subquery; PlannerInfo subroot;
Plan *subplan; Plan *subplan;
/* Generate modified query with this rel as target */ /*
subquery = (Query *) adjust_inherited_attrs((Node *) parse, * Generate modified query with this rel as target. We have to
parentRTindex, parentOID, * be prepared to translate varnos in in_info_list as well as in
childRTindex, childOID); * the Query proper.
*/
memcpy(&subroot, root, sizeof(PlannerInfo));
subroot.parse = (Query *)
adjust_inherited_attrs((Node *) parse,
parentRTindex, parentOID,
childRTindex, childOID);
subroot.in_info_list = (List *)
adjust_inherited_attrs((Node *) root->in_info_list,
parentRTindex, parentOID,
childRTindex, childOID);
/* Generate plan */ /* Generate plan */
subplan = grouping_planner(subquery, 0.0 /* retrieve all tuples */ ); subplan = grouping_planner(&subroot, 0.0 /* retrieve all tuples */ );
subplans = lappend(subplans, subplan); subplans = lappend(subplans, subplan);
/* /*
...@@ -565,16 +591,16 @@ inheritance_planner(Query *parse, List *inheritlist) ...@@ -565,16 +591,16 @@ inheritance_planner(Query *parse, List *inheritlist)
* rangetables will be the same each time. Did I say this is ugly?) * rangetables will be the same each time. Did I say this is ugly?)
*/ */
if (lnext(l) == NULL) if (lnext(l) == NULL)
parse->rtable = subquery->rtable; parse->rtable = subroot.parse->rtable;
else else
{ {
int subrtlength = list_length(subquery->rtable); int subrtlength = list_length(subroot.parse->rtable);
if (subrtlength > mainrtlength) if (subrtlength > mainrtlength)
{ {
List *subrt; List *subrt;
subrt = list_copy_tail(subquery->rtable, mainrtlength); subrt = list_copy_tail(subroot.parse->rtable, mainrtlength);
parse->rtable = list_concat(parse->rtable, subrt); parse->rtable = list_concat(parse->rtable, subrt);
mainrtlength = subrtlength; mainrtlength = subrtlength;
} }
...@@ -589,7 +615,7 @@ inheritance_planner(Query *parse, List *inheritlist) ...@@ -589,7 +615,7 @@ inheritance_planner(Query *parse, List *inheritlist)
parse->resultRelations = inheritlist; parse->resultRelations = inheritlist;
/* Mark result as unordered (probably unnecessary) */ /* Mark result as unordered (probably unnecessary) */
parse->query_pathkeys = NIL; root->query_pathkeys = NIL;
return (Plan *) make_append(subplans, true, tlist); return (Plan *) make_append(subplans, true, tlist);
} }
...@@ -600,7 +626,6 @@ inheritance_planner(Query *parse, List *inheritlist) ...@@ -600,7 +626,6 @@ inheritance_planner(Query *parse, List *inheritlist)
* This primarily means adding top-level processing to the basic * This primarily means adding top-level processing to the basic
* query plan produced by query_planner. * query plan produced by query_planner.
* *
* parse is the querytree produced by the parser & rewriter.
* tuple_fraction is the fraction of tuples we expect will be retrieved * tuple_fraction is the fraction of tuples we expect will be retrieved
* *
* tuple_fraction is interpreted as follows: * tuple_fraction is interpreted as follows:
...@@ -610,13 +635,14 @@ inheritance_planner(Query *parse, List *inheritlist) ...@@ -610,13 +635,14 @@ inheritance_planner(Query *parse, List *inheritlist)
* tuple_fraction >= 1: tuple_fraction is the absolute number of tuples * tuple_fraction >= 1: tuple_fraction is the absolute number of tuples
* expected to be retrieved (ie, a LIMIT specification) * expected to be retrieved (ie, a LIMIT specification)
* *
* Returns a query plan. Also, parse->query_pathkeys is returned as the * Returns a query plan. Also, root->query_pathkeys is returned as the
* actual output ordering of the plan (in pathkey format). * actual output ordering of the plan (in pathkey format).
*-------------------- *--------------------
*/ */
static Plan * static Plan *
grouping_planner(Query *parse, double tuple_fraction) grouping_planner(PlannerInfo *root, double tuple_fraction)
{ {
Query *parse = root->parse;
List *tlist = parse->targetList; List *tlist = parse->targetList;
Plan *result_plan; Plan *result_plan;
List *current_pathkeys; List *current_pathkeys;
...@@ -630,7 +656,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -630,7 +656,7 @@ grouping_planner(Query *parse, double tuple_fraction)
* Construct the plan for set operations. The result will not * Construct the plan for set operations. The result will not
* need any work except perhaps a top-level sort and/or LIMIT. * need any work except perhaps a top-level sort and/or LIMIT.
*/ */
result_plan = plan_set_operations(parse, result_plan = plan_set_operations(root,
&set_sortclauses); &set_sortclauses);
/* /*
...@@ -640,7 +666,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -640,7 +666,7 @@ grouping_planner(Query *parse, double tuple_fraction)
*/ */
current_pathkeys = make_pathkeys_for_sortclauses(set_sortclauses, current_pathkeys = make_pathkeys_for_sortclauses(set_sortclauses,
result_plan->targetlist); result_plan->targetlist);
current_pathkeys = canonicalize_pathkeys(parse, current_pathkeys); current_pathkeys = canonicalize_pathkeys(root, current_pathkeys);
/* /*
* We should not need to call preprocess_targetlist, since we must * We should not need to call preprocess_targetlist, since we must
...@@ -667,7 +693,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -667,7 +693,7 @@ grouping_planner(Query *parse, double tuple_fraction)
*/ */
sort_pathkeys = make_pathkeys_for_sortclauses(parse->sortClause, sort_pathkeys = make_pathkeys_for_sortclauses(parse->sortClause,
tlist); tlist);
sort_pathkeys = canonicalize_pathkeys(parse, sort_pathkeys); sort_pathkeys = canonicalize_pathkeys(root, sort_pathkeys);
} }
else else
{ {
...@@ -690,13 +716,13 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -690,13 +716,13 @@ grouping_planner(Query *parse, double tuple_fraction)
MemSet(&agg_counts, 0, sizeof(AggClauseCounts)); MemSet(&agg_counts, 0, sizeof(AggClauseCounts));
/* Preprocess targetlist */ /* Preprocess targetlist */
tlist = preprocess_targetlist(parse, tlist); tlist = preprocess_targetlist(root, tlist);
/* /*
* Generate appropriate target list for subplan; may be different * Generate appropriate target list for subplan; may be different
* from tlist if grouping or aggregation is needed. * from tlist if grouping or aggregation is needed.
*/ */
sub_tlist = make_subplanTargetList(parse, tlist, sub_tlist = make_subplanTargetList(root, tlist,
&groupColIdx, &need_tlist_eval); &groupColIdx, &need_tlist_eval);
/* /*
...@@ -737,11 +763,11 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -737,11 +763,11 @@ grouping_planner(Query *parse, double tuple_fraction)
* Needs more thought...) * Needs more thought...)
*/ */
if (parse->groupClause) if (parse->groupClause)
parse->query_pathkeys = group_pathkeys; root->query_pathkeys = group_pathkeys;
else if (parse->sortClause) else if (parse->sortClause)
parse->query_pathkeys = sort_pathkeys; root->query_pathkeys = sort_pathkeys;
else else
parse->query_pathkeys = NIL; root->query_pathkeys = NIL;
/* /*
* Adjust tuple_fraction if we see that we are going to apply * Adjust tuple_fraction if we see that we are going to apply
...@@ -902,15 +928,15 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -902,15 +928,15 @@ grouping_planner(Query *parse, double tuple_fraction)
* Generate the best unsorted and presorted paths for this Query * Generate the best unsorted and presorted paths for this Query
* (but note there may not be any presorted path). * (but note there may not be any presorted path).
*/ */
query_planner(parse, sub_tlist, sub_tuple_fraction, query_planner(root, sub_tlist, sub_tuple_fraction,
&cheapest_path, &sorted_path); &cheapest_path, &sorted_path);
/* /*
* We couldn't canonicalize group_pathkeys and sort_pathkeys * We couldn't canonicalize group_pathkeys and sort_pathkeys
* before running query_planner(), so do it now. * before running query_planner(), so do it now.
*/ */
group_pathkeys = canonicalize_pathkeys(parse, group_pathkeys); group_pathkeys = canonicalize_pathkeys(root, group_pathkeys);
sort_pathkeys = canonicalize_pathkeys(parse, sort_pathkeys); sort_pathkeys = canonicalize_pathkeys(root, sort_pathkeys);
/* /*
* If grouping, estimate the number of groups. (We can't do this * If grouping, estimate the number of groups. (We can't do this
...@@ -934,14 +960,14 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -934,14 +960,14 @@ grouping_planner(Query *parse, double tuple_fraction)
groupExprs = get_sortgrouplist_exprs(parse->groupClause, groupExprs = get_sortgrouplist_exprs(parse->groupClause,
parse->targetList); parse->targetList);
dNumGroups = estimate_num_groups(parse, dNumGroups = estimate_num_groups(root,
groupExprs, groupExprs,
cheapest_path_rows); cheapest_path_rows);
/* Also want it as a long int --- but 'ware overflow! */ /* Also want it as a long int --- but 'ware overflow! */
numGroups = (long) Min(dNumGroups, (double) LONG_MAX); numGroups = (long) Min(dNumGroups, (double) LONG_MAX);
use_hashed_grouping = use_hashed_grouping =
choose_hashed_grouping(parse, tuple_fraction, choose_hashed_grouping(root, tuple_fraction,
cheapest_path, sorted_path, cheapest_path, sorted_path,
sort_pathkeys, group_pathkeys, sort_pathkeys, group_pathkeys,
dNumGroups, &agg_counts); dNumGroups, &agg_counts);
...@@ -963,7 +989,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -963,7 +989,7 @@ grouping_planner(Query *parse, double tuple_fraction)
* "regular" path ... but we had to do it anyway to be able to * "regular" path ... but we had to do it anyway to be able to
* tell which way is cheaper. * tell which way is cheaper.
*/ */
result_plan = optimize_minmax_aggregates(parse, result_plan = optimize_minmax_aggregates(root,
tlist, tlist,
best_path); best_path);
if (result_plan != NULL) if (result_plan != NULL)
...@@ -980,7 +1006,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -980,7 +1006,7 @@ grouping_planner(Query *parse, double tuple_fraction)
* Normal case --- create a plan according to query_planner's * Normal case --- create a plan according to query_planner's
* results. * results.
*/ */
result_plan = create_plan(parse, best_path); result_plan = create_plan(root, best_path);
current_pathkeys = best_path->pathkeys; current_pathkeys = best_path->pathkeys;
/* /*
...@@ -1042,7 +1068,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1042,7 +1068,7 @@ grouping_planner(Query *parse, double tuple_fraction)
* make_subplanTargetList calculated, we have to refigure any * make_subplanTargetList calculated, we have to refigure any
* grouping-column indexes make_subplanTargetList computed. * grouping-column indexes make_subplanTargetList computed.
*/ */
locate_grouping_columns(parse, tlist, result_plan->targetlist, locate_grouping_columns(root, tlist, result_plan->targetlist,
groupColIdx); groupColIdx);
} }
...@@ -1055,7 +1081,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1055,7 +1081,7 @@ grouping_planner(Query *parse, double tuple_fraction)
if (use_hashed_grouping) if (use_hashed_grouping)
{ {
/* Hashed aggregate plan --- no sort needed */ /* Hashed aggregate plan --- no sort needed */
result_plan = (Plan *) make_agg(parse, result_plan = (Plan *) make_agg(root,
tlist, tlist,
(List *) parse->havingQual, (List *) parse->havingQual,
AGG_HASHED, AGG_HASHED,
...@@ -1078,7 +1104,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1078,7 +1104,7 @@ grouping_planner(Query *parse, double tuple_fraction)
current_pathkeys)) current_pathkeys))
{ {
result_plan = (Plan *) result_plan = (Plan *)
make_sort_from_groupcols(parse, make_sort_from_groupcols(root,
parse->groupClause, parse->groupClause,
groupColIdx, groupColIdx,
result_plan); result_plan);
...@@ -1098,7 +1124,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1098,7 +1124,7 @@ grouping_planner(Query *parse, double tuple_fraction)
current_pathkeys = NIL; current_pathkeys = NIL;
} }
result_plan = (Plan *) make_agg(parse, result_plan = (Plan *) make_agg(root,
tlist, tlist,
(List *) parse->havingQual, (List *) parse->havingQual,
aggstrategy, aggstrategy,
...@@ -1120,14 +1146,14 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1120,14 +1146,14 @@ grouping_planner(Query *parse, double tuple_fraction)
if (!pathkeys_contained_in(group_pathkeys, current_pathkeys)) if (!pathkeys_contained_in(group_pathkeys, current_pathkeys))
{ {
result_plan = (Plan *) result_plan = (Plan *)
make_sort_from_groupcols(parse, make_sort_from_groupcols(root,
parse->groupClause, parse->groupClause,
groupColIdx, groupColIdx,
result_plan); result_plan);
current_pathkeys = group_pathkeys; current_pathkeys = group_pathkeys;
} }
result_plan = (Plan *) make_group(parse, result_plan = (Plan *) make_group(root,
tlist, tlist,
(List *) parse->havingQual, (List *) parse->havingQual,
numGroupCols, numGroupCols,
...@@ -1136,7 +1162,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1136,7 +1162,7 @@ grouping_planner(Query *parse, double tuple_fraction)
result_plan); result_plan);
/* The Group node won't change sort ordering */ /* The Group node won't change sort ordering */
} }
else if (parse->hasHavingQual) else if (root->hasHavingQual)
{ {
/* /*
* No aggregates, and no GROUP BY, but we have a HAVING qual. * No aggregates, and no GROUP BY, but we have a HAVING qual.
...@@ -1165,7 +1191,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1165,7 +1191,7 @@ grouping_planner(Query *parse, double tuple_fraction)
if (!pathkeys_contained_in(sort_pathkeys, current_pathkeys)) if (!pathkeys_contained_in(sort_pathkeys, current_pathkeys))
{ {
result_plan = (Plan *) result_plan = (Plan *)
make_sort_from_sortclauses(parse, make_sort_from_sortclauses(root,
parse->sortClause, parse->sortClause,
result_plan); result_plan);
current_pathkeys = sort_pathkeys; current_pathkeys = sort_pathkeys;
...@@ -1185,13 +1211,13 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1185,13 +1211,13 @@ grouping_planner(Query *parse, double tuple_fraction)
* it's reasonable to assume the UNIQUE filter has effects * it's reasonable to assume the UNIQUE filter has effects
* comparable to GROUP BY. * comparable to GROUP BY.
*/ */
if (!parse->groupClause && !parse->hasHavingQual && !parse->hasAggs) if (!parse->groupClause && !root->hasHavingQual && !parse->hasAggs)
{ {
List *distinctExprs; List *distinctExprs;
distinctExprs = get_sortgrouplist_exprs(parse->distinctClause, distinctExprs = get_sortgrouplist_exprs(parse->distinctClause,
parse->targetList); parse->targetList);
result_plan->plan_rows = estimate_num_groups(parse, result_plan->plan_rows = estimate_num_groups(root,
distinctExprs, distinctExprs,
result_plan->plan_rows); result_plan->plan_rows);
} }
...@@ -1211,7 +1237,7 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1211,7 +1237,7 @@ grouping_planner(Query *parse, double tuple_fraction)
* Return the actual output ordering in query_pathkeys for possible * Return the actual output ordering in query_pathkeys for possible
* use by an outer query level. * use by an outer query level.
*/ */
parse->query_pathkeys = current_pathkeys; root->query_pathkeys = current_pathkeys;
return result_plan; return result_plan;
} }
...@@ -1220,12 +1246,12 @@ grouping_planner(Query *parse, double tuple_fraction) ...@@ -1220,12 +1246,12 @@ grouping_planner(Query *parse, double tuple_fraction)
* choose_hashed_grouping - should we use hashed grouping? * choose_hashed_grouping - should we use hashed grouping?
*/ */
static bool static bool
choose_hashed_grouping(Query *parse, double tuple_fraction, choose_hashed_grouping(PlannerInfo *root, double tuple_fraction,
Path *cheapest_path, Path *sorted_path, Path *cheapest_path, Path *sorted_path,
List *sort_pathkeys, List *group_pathkeys, List *sort_pathkeys, List *group_pathkeys,
double dNumGroups, AggClauseCounts *agg_counts) double dNumGroups, AggClauseCounts *agg_counts)
{ {
int numGroupCols = list_length(parse->groupClause); int numGroupCols = list_length(root->parse->groupClause);
double cheapest_path_rows; double cheapest_path_rows;
int cheapest_path_width; int cheapest_path_width;
Size hashentrysize; Size hashentrysize;
...@@ -1245,7 +1271,7 @@ choose_hashed_grouping(Query *parse, double tuple_fraction, ...@@ -1245,7 +1271,7 @@ choose_hashed_grouping(Query *parse, double tuple_fraction,
return false; return false;
if (agg_counts->numDistinctAggs != 0) if (agg_counts->numDistinctAggs != 0)
return false; return false;
if (!hash_safe_grouping(parse)) if (!hash_safe_grouping(root))
return false; return false;
/* /*
...@@ -1296,13 +1322,13 @@ choose_hashed_grouping(Query *parse, double tuple_fraction, ...@@ -1296,13 +1322,13 @@ choose_hashed_grouping(Query *parse, double tuple_fraction,
* These path variables are dummies that just hold cost fields; we don't * These path variables are dummies that just hold cost fields; we don't
* make actual Paths for these steps. * make actual Paths for these steps.
*/ */
cost_agg(&hashed_p, parse, AGG_HASHED, agg_counts->numAggs, cost_agg(&hashed_p, root, AGG_HASHED, agg_counts->numAggs,
numGroupCols, dNumGroups, numGroupCols, dNumGroups,
cheapest_path->startup_cost, cheapest_path->total_cost, cheapest_path->startup_cost, cheapest_path->total_cost,
cheapest_path_rows); cheapest_path_rows);
/* Result of hashed agg is always unsorted */ /* Result of hashed agg is always unsorted */
if (sort_pathkeys) if (sort_pathkeys)
cost_sort(&hashed_p, parse, sort_pathkeys, hashed_p.total_cost, cost_sort(&hashed_p, root, sort_pathkeys, hashed_p.total_cost,
dNumGroups, cheapest_path_width); dNumGroups, cheapest_path_width);
if (sorted_path) if (sorted_path)
...@@ -1320,24 +1346,24 @@ choose_hashed_grouping(Query *parse, double tuple_fraction, ...@@ -1320,24 +1346,24 @@ choose_hashed_grouping(Query *parse, double tuple_fraction,
if (!pathkeys_contained_in(group_pathkeys, if (!pathkeys_contained_in(group_pathkeys,
current_pathkeys)) current_pathkeys))
{ {
cost_sort(&sorted_p, parse, group_pathkeys, sorted_p.total_cost, cost_sort(&sorted_p, root, group_pathkeys, sorted_p.total_cost,
cheapest_path_rows, cheapest_path_width); cheapest_path_rows, cheapest_path_width);
current_pathkeys = group_pathkeys; current_pathkeys = group_pathkeys;
} }
if (parse->hasAggs) if (root->parse->hasAggs)
cost_agg(&sorted_p, parse, AGG_SORTED, agg_counts->numAggs, cost_agg(&sorted_p, root, AGG_SORTED, agg_counts->numAggs,
numGroupCols, dNumGroups, numGroupCols, dNumGroups,
sorted_p.startup_cost, sorted_p.total_cost, sorted_p.startup_cost, sorted_p.total_cost,
cheapest_path_rows); cheapest_path_rows);
else else
cost_group(&sorted_p, parse, numGroupCols, dNumGroups, cost_group(&sorted_p, root, numGroupCols, dNumGroups,
sorted_p.startup_cost, sorted_p.total_cost, sorted_p.startup_cost, sorted_p.total_cost,
cheapest_path_rows); cheapest_path_rows);
/* The Agg or Group node will preserve ordering */ /* The Agg or Group node will preserve ordering */
if (sort_pathkeys && if (sort_pathkeys &&
!pathkeys_contained_in(sort_pathkeys, current_pathkeys)) !pathkeys_contained_in(sort_pathkeys, current_pathkeys))
cost_sort(&sorted_p, parse, sort_pathkeys, sorted_p.total_cost, cost_sort(&sorted_p, root, sort_pathkeys, sorted_p.total_cost,
dNumGroups, cheapest_path_width); dNumGroups, cheapest_path_width);
/* /*
...@@ -1363,14 +1389,15 @@ choose_hashed_grouping(Query *parse, double tuple_fraction, ...@@ -1363,14 +1389,15 @@ choose_hashed_grouping(Query *parse, double tuple_fraction,
* is marked hashjoinable. * is marked hashjoinable.
*/ */
static bool static bool
hash_safe_grouping(Query *parse) hash_safe_grouping(PlannerInfo *root)
{ {
ListCell *gl; ListCell *gl;
foreach(gl, parse->groupClause) foreach(gl, root->parse->groupClause)
{ {
GroupClause *grpcl = (GroupClause *) lfirst(gl); GroupClause *grpcl = (GroupClause *) lfirst(gl);
TargetEntry *tle = get_sortgroupclause_tle(grpcl, parse->targetList); TargetEntry *tle = get_sortgroupclause_tle(grpcl,
root->parse->targetList);
Operator optup; Operator optup;
bool oprcanhash; bool oprcanhash;
...@@ -1417,7 +1444,6 @@ hash_safe_grouping(Query *parse) ...@@ -1417,7 +1444,6 @@ hash_safe_grouping(Query *parse)
* need to force it to be evaluated, because all the Vars it contains * need to force it to be evaluated, because all the Vars it contains
* should be present in the output of query_planner anyway. * should be present in the output of query_planner anyway.
* *
* 'parse' is the query being processed.
* 'tlist' is the query's target list. * 'tlist' is the query's target list.
* 'groupColIdx' receives an array of column numbers for the GROUP BY * 'groupColIdx' receives an array of column numbers for the GROUP BY
* expressions (if there are any) in the subplan's target list. * expressions (if there are any) in the subplan's target list.
...@@ -1428,11 +1454,12 @@ hash_safe_grouping(Query *parse) ...@@ -1428,11 +1454,12 @@ hash_safe_grouping(Query *parse)
*--------------- *---------------
*/ */
static List * static List *
make_subplanTargetList(Query *parse, make_subplanTargetList(PlannerInfo *root,
List *tlist, List *tlist,
AttrNumber **groupColIdx, AttrNumber **groupColIdx,
bool *need_tlist_eval) bool *need_tlist_eval)
{ {
Query *parse = root->parse;
List *sub_tlist; List *sub_tlist;
List *extravars; List *extravars;
int numCols; int numCols;
...@@ -1443,7 +1470,7 @@ make_subplanTargetList(Query *parse, ...@@ -1443,7 +1470,7 @@ make_subplanTargetList(Query *parse,
* If we're not grouping or aggregating, there's nothing to do here; * If we're not grouping or aggregating, there's nothing to do here;
* query_planner should receive the unmodified target list. * query_planner should receive the unmodified target list.
*/ */
if (!parse->hasAggs && !parse->groupClause && !parse->hasHavingQual) if (!parse->hasAggs && !parse->groupClause && !root->hasHavingQual)
{ {
*need_tlist_eval = true; *need_tlist_eval = true;
return tlist; return tlist;
...@@ -1517,7 +1544,7 @@ make_subplanTargetList(Query *parse, ...@@ -1517,7 +1544,7 @@ make_subplanTargetList(Query *parse,
* by that routine and re-locate the grouping vars in the real sub_tlist. * by that routine and re-locate the grouping vars in the real sub_tlist.
*/ */
static void static void
locate_grouping_columns(Query *parse, locate_grouping_columns(PlannerInfo *root,
List *tlist, List *tlist,
List *sub_tlist, List *sub_tlist,
AttrNumber *groupColIdx) AttrNumber *groupColIdx)
...@@ -1528,14 +1555,14 @@ locate_grouping_columns(Query *parse, ...@@ -1528,14 +1555,14 @@ locate_grouping_columns(Query *parse,
/* /*
* No work unless grouping. * No work unless grouping.
*/ */
if (!parse->groupClause) if (!root->parse->groupClause)
{ {
Assert(groupColIdx == NULL); Assert(groupColIdx == NULL);
return; return;
} }
Assert(groupColIdx != NULL); Assert(groupColIdx != NULL);
foreach(gl, parse->groupClause) foreach(gl, root->parse->groupClause)
{ {
GroupClause *grpcl = (GroupClause *) lfirst(gl); GroupClause *grpcl = (GroupClause *) lfirst(gl);
Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist); Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.98 2005/04/25 01:30:13 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.99 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -292,7 +292,7 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual) ...@@ -292,7 +292,7 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
/* /*
* Generate the plan for the subquery. * Generate the plan for the subquery.
*/ */
node->plan = plan = subquery_planner(subquery, tuple_fraction); node->plan = plan = subquery_planner(subquery, tuple_fraction, NULL);
node->plan_id = PlannerPlanId++; /* Assign unique ID to this node->plan_id = PlannerPlanId++; /* Assign unique ID to this
* SubPlan */ * SubPlan */
...@@ -417,10 +417,8 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual) ...@@ -417,10 +417,8 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
* top of the subplan, to reduce the cost of reading it * top of the subplan, to reduce the cost of reading it
* repeatedly. This is pointless for a direct-correlated subplan, * repeatedly. This is pointless for a direct-correlated subplan,
* since we'd have to recompute its results each time anyway. For * since we'd have to recompute its results each time anyway. For
* uncorrelated/undirect correlated subplans, we add MATERIAL if * uncorrelated/undirect correlated subplans, we add MATERIAL unless
* the subplan's top plan node is anything more complicated than a * the subplan's top plan node would materialize its output anyway.
* plain sequential scan, and we do it even for seqscan if the
* qual appears selective enough to eliminate many tuples.
*/ */
else if (node->parParam == NIL) else if (node->parParam == NIL)
{ {
...@@ -428,29 +426,9 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual) ...@@ -428,29 +426,9 @@ make_subplan(SubLink *slink, List *lefthand, bool isTopQual)
switch (nodeTag(plan)) switch (nodeTag(plan))
{ {
case T_SeqScan:
if (plan->initPlan)
use_material = true;
else
{
Selectivity qualsel;
qualsel = clauselist_selectivity(subquery,
plan->qual,
0, JOIN_INNER);
/* Is 10% selectivity a good threshold?? */
use_material = qualsel < 0.10;
}
break;
case T_Material: case T_Material:
case T_FunctionScan: case T_FunctionScan:
case T_Sort: case T_Sort:
/*
* Don't add another Material node if there's one
* already, nor if the top node is any other type that
* materializes its output anyway.
*/
use_material = false; use_material = false;
break; break;
default: default:
...@@ -678,8 +656,9 @@ subplan_is_hashable(SubLink *slink, SubPlan *node) ...@@ -678,8 +656,9 @@ subplan_is_hashable(SubLink *slink, SubPlan *node)
* its in_info_list. * its in_info_list.
*/ */
Node * Node *
convert_IN_to_join(Query *parse, SubLink *sublink) convert_IN_to_join(PlannerInfo *root, SubLink *sublink)
{ {
Query *parse = root->parse;
Query *subselect = (Query *) sublink->subselect; Query *subselect = (Query *) sublink->subselect;
Relids left_varnos; Relids left_varnos;
int rtindex; int rtindex;
...@@ -746,7 +725,7 @@ convert_IN_to_join(Query *parse, SubLink *sublink) ...@@ -746,7 +725,7 @@ convert_IN_to_join(Query *parse, SubLink *sublink)
ininfo = makeNode(InClauseInfo); ininfo = makeNode(InClauseInfo);
ininfo->lefthand = left_varnos; ininfo->lefthand = left_varnos;
ininfo->righthand = bms_make_singleton(rtindex); ininfo->righthand = bms_make_singleton(rtindex);
parse->in_info_list = lcons(ininfo, parse->in_info_list); root->in_info_list = lappend(root->in_info_list, ininfo);
/* /*
* Build the result qual expressions. As a side effect, * Build the result qual expressions. As a side effect,
...@@ -1252,7 +1231,7 @@ finalize_primnode(Node *node, finalize_primnode_context *context) ...@@ -1252,7 +1231,7 @@ finalize_primnode(Node *node, finalize_primnode_context *context)
* We assume the plan hasn't been put through SS_finalize_plan. * We assume the plan hasn't been put through SS_finalize_plan.
*/ */
Param * Param *
SS_make_initplan_from_plan(Query *root, Plan *plan, SS_make_initplan_from_plan(PlannerInfo *root, Plan *plan,
Oid resulttype, int32 resulttypmod) Oid resulttype, int32 resulttypmod)
{ {
List *saved_initplan = PlannerInitPlan; List *saved_initplan = PlannerInitPlan;
...@@ -1271,7 +1250,7 @@ SS_make_initplan_from_plan(Query *root, Plan *plan, ...@@ -1271,7 +1250,7 @@ SS_make_initplan_from_plan(Query *root, Plan *plan,
/* /*
* Build extParam/allParam sets for plan nodes. * Build extParam/allParam sets for plan nodes.
*/ */
SS_finalize_plan(plan, root->rtable); SS_finalize_plan(plan, root->parse->rtable);
/* Return to outer subquery context */ /* Return to outer subquery context */
PlannerQueryLevel--; PlannerQueryLevel--;
...@@ -1286,7 +1265,7 @@ SS_make_initplan_from_plan(Query *root, Plan *plan, ...@@ -1286,7 +1265,7 @@ SS_make_initplan_from_plan(Query *root, Plan *plan,
node->plan_id = PlannerPlanId++; /* Assign unique ID to this node->plan_id = PlannerPlanId++; /* Assign unique ID to this
* SubPlan */ * SubPlan */
node->rtable = root->rtable; node->rtable = root->parse->rtable;
PlannerInitPlan = lappend(PlannerInitPlan, node); PlannerInitPlan = lappend(PlannerInitPlan, node);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.28 2005/06/04 19:19:41 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.29 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -50,7 +50,7 @@ static void resolvenew_in_jointree(Node *jtnode, int varno, ...@@ -50,7 +50,7 @@ static void resolvenew_in_jointree(Node *jtnode, int varno,
static reduce_outer_joins_state *reduce_outer_joins_pass1(Node *jtnode); static reduce_outer_joins_state *reduce_outer_joins_pass1(Node *jtnode);
static void reduce_outer_joins_pass2(Node *jtnode, static void reduce_outer_joins_pass2(Node *jtnode,
reduce_outer_joins_state *state, reduce_outer_joins_state *state,
Query *parse, PlannerInfo *root,
Relids nonnullable_rels); Relids nonnullable_rels);
static Relids find_nonnullable_rels(Node *node, bool top_level); static Relids find_nonnullable_rels(Node *node, bool top_level);
static void fix_in_clause_relids(List *in_info_list, int varno, static void fix_in_clause_relids(List *in_info_list, int varno,
...@@ -79,7 +79,7 @@ static Node *find_jointree_node_for_rel(Node *jtnode, int relid); ...@@ -79,7 +79,7 @@ static Node *find_jointree_node_for_rel(Node *jtnode, int relid);
* Returns the possibly-modified version of the given qual-tree node. * Returns the possibly-modified version of the given qual-tree node.
*/ */
Node * Node *
pull_up_IN_clauses(Query *parse, Node *node) pull_up_IN_clauses(PlannerInfo *root, Node *node)
{ {
if (node == NULL) if (node == NULL)
return NULL; return NULL;
...@@ -89,7 +89,7 @@ pull_up_IN_clauses(Query *parse, Node *node) ...@@ -89,7 +89,7 @@ pull_up_IN_clauses(Query *parse, Node *node)
Node *subst; Node *subst;
/* Is it a convertible IN clause? If not, return it as-is */ /* Is it a convertible IN clause? If not, return it as-is */
subst = convert_IN_to_join(parse, sublink); subst = convert_IN_to_join(root, sublink);
if (subst == NULL) if (subst == NULL)
return node; return node;
return subst; return subst;
...@@ -104,8 +104,7 @@ pull_up_IN_clauses(Query *parse, Node *node) ...@@ -104,8 +104,7 @@ pull_up_IN_clauses(Query *parse, Node *node)
Node *oldclause = (Node *) lfirst(l); Node *oldclause = (Node *) lfirst(l);
newclauses = lappend(newclauses, newclauses = lappend(newclauses,
pull_up_IN_clauses(parse, pull_up_IN_clauses(root, oldclause));
oldclause));
} }
return (Node *) make_andclause(newclauses); return (Node *) make_andclause(newclauses);
} }
...@@ -132,13 +131,14 @@ pull_up_IN_clauses(Query *parse, Node *node) ...@@ -132,13 +131,14 @@ pull_up_IN_clauses(Query *parse, Node *node)
* copy of the tree; we have to invoke it just on the quals, instead. * copy of the tree; we have to invoke it just on the quals, instead.
*/ */
Node * Node *
pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) pull_up_subqueries(PlannerInfo *root, Node *jtnode, bool below_outer_join)
{ {
if (jtnode == NULL) if (jtnode == NULL)
return NULL; return NULL;
if (IsA(jtnode, RangeTblRef)) if (IsA(jtnode, RangeTblRef))
{ {
int varno = ((RangeTblRef *) jtnode)->rtindex; int varno = ((RangeTblRef *) jtnode)->rtindex;
Query *parse = root->parse;
RangeTblEntry *rte = rt_fetch(varno, parse->rtable); RangeTblEntry *rte = rt_fetch(varno, parse->rtable);
Query *subquery = rte->subquery; Query *subquery = rte->subquery;
...@@ -160,6 +160,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -160,6 +160,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
is_simple_subquery(subquery) && is_simple_subquery(subquery) &&
(!below_outer_join || has_nullable_targetlist(subquery))) (!below_outer_join || has_nullable_targetlist(subquery)))
{ {
PlannerInfo *subroot;
int rtoffset; int rtoffset;
List *subtlist; List *subtlist;
ListCell *rt; ListCell *rt;
...@@ -173,12 +174,23 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -173,12 +174,23 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
*/ */
subquery = copyObject(subquery); subquery = copyObject(subquery);
/*
* Create a PlannerInfo data structure for this subquery.
*
* NOTE: the next few steps should match the first processing
* in subquery_planner(). Can we refactor to avoid code
* duplication, or would that just make things uglier?
*/
subroot = makeNode(PlannerInfo);
subroot->parse = subquery;
/* /*
* Pull up any IN clauses within the subquery's WHERE, so that * Pull up any IN clauses within the subquery's WHERE, so that
* we don't leave unoptimized INs behind. * we don't leave unoptimized INs behind.
*/ */
subroot->in_info_list = NIL;
if (subquery->hasSubLinks) if (subquery->hasSubLinks)
subquery->jointree->quals = pull_up_IN_clauses(subquery, subquery->jointree->quals = pull_up_IN_clauses(subroot,
subquery->jointree->quals); subquery->jointree->quals);
/* /*
...@@ -191,7 +203,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -191,7 +203,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
* clean slate for outer-join semantics. * clean slate for outer-join semantics.
*/ */
subquery->jointree = (FromExpr *) subquery->jointree = (FromExpr *)
pull_up_subqueries(subquery, (Node *) subquery->jointree, pull_up_subqueries(subroot, (Node *) subquery->jointree,
false); false);
/* /*
...@@ -222,16 +234,19 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -222,16 +234,19 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
/* /*
* Adjust level-0 varnos in subquery so that we can append its * Adjust level-0 varnos in subquery so that we can append its
* rangetable to upper query's. * rangetable to upper query's. We have to fix the subquery's
* in_info_list, as well.
*/ */
rtoffset = list_length(parse->rtable); rtoffset = list_length(parse->rtable);
OffsetVarNodes((Node *) subquery, rtoffset, 0); OffsetVarNodes((Node *) subquery, rtoffset, 0);
OffsetVarNodes((Node *) subroot->in_info_list, rtoffset, 0);
/* /*
* Upper-level vars in subquery are now one level closer to * Upper-level vars in subquery are now one level closer to
* their parent than before. * their parent than before.
*/ */
IncrementVarSublevelsUp((Node *) subquery, -1, 1); IncrementVarSublevelsUp((Node *) subquery, -1, 1);
IncrementVarSublevelsUp((Node *) subroot->in_info_list, -1, 1);
/* /*
* Replace all of the top query's references to the subquery's * Replace all of the top query's references to the subquery's
...@@ -252,8 +267,8 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -252,8 +267,8 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
ResolveNew(parse->havingQual, ResolveNew(parse->havingQual,
varno, 0, rte, varno, 0, rte,
subtlist, CMD_SELECT, 0); subtlist, CMD_SELECT, 0);
parse->in_info_list = (List *) root->in_info_list = (List *)
ResolveNew((Node *) parse->in_info_list, ResolveNew((Node *) root->in_info_list,
varno, 0, rte, varno, 0, rte,
subtlist, CMD_SELECT, 0); subtlist, CMD_SELECT, 0);
...@@ -299,19 +314,19 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -299,19 +314,19 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
* ResolveNew, but it would clutter that routine's API * ResolveNew, but it would clutter that routine's API
* unreasonably.) * unreasonably.)
*/ */
if (parse->in_info_list) if (root->in_info_list)
{ {
Relids subrelids; Relids subrelids;
subrelids = get_relids_in_jointree((Node *) subquery->jointree); subrelids = get_relids_in_jointree((Node *) subquery->jointree);
fix_in_clause_relids(parse->in_info_list, varno, subrelids); fix_in_clause_relids(root->in_info_list, varno, subrelids);
} }
/* /*
* And now append any subquery InClauseInfos to our list. * And now append any subquery InClauseInfos to our list.
*/ */
parse->in_info_list = list_concat(parse->in_info_list, root->in_info_list = list_concat(root->in_info_list,
subquery->in_info_list); subroot->in_info_list);
/* /*
* Miscellaneous housekeeping. * Miscellaneous housekeeping.
...@@ -332,7 +347,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -332,7 +347,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
ListCell *l; ListCell *l;
foreach(l, f->fromlist) foreach(l, f->fromlist)
lfirst(l) = pull_up_subqueries(parse, lfirst(l), lfirst(l) = pull_up_subqueries(root, lfirst(l),
below_outer_join); below_outer_join);
} }
else if (IsA(jtnode, JoinExpr)) else if (IsA(jtnode, JoinExpr))
...@@ -343,27 +358,27 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join) ...@@ -343,27 +358,27 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
switch (j->jointype) switch (j->jointype)
{ {
case JOIN_INNER: case JOIN_INNER:
j->larg = pull_up_subqueries(parse, j->larg, j->larg = pull_up_subqueries(root, j->larg,
below_outer_join); below_outer_join);
j->rarg = pull_up_subqueries(parse, j->rarg, j->rarg = pull_up_subqueries(root, j->rarg,
below_outer_join); below_outer_join);
break; break;
case JOIN_LEFT: case JOIN_LEFT:
j->larg = pull_up_subqueries(parse, j->larg, j->larg = pull_up_subqueries(root, j->larg,
below_outer_join); below_outer_join);
j->rarg = pull_up_subqueries(parse, j->rarg, j->rarg = pull_up_subqueries(root, j->rarg,
true); true);
break; break;
case JOIN_FULL: case JOIN_FULL:
j->larg = pull_up_subqueries(parse, j->larg, j->larg = pull_up_subqueries(root, j->larg,
true); true);
j->rarg = pull_up_subqueries(parse, j->rarg, j->rarg = pull_up_subqueries(root, j->rarg,
true); true);
break; break;
case JOIN_RIGHT: case JOIN_RIGHT:
j->larg = pull_up_subqueries(parse, j->larg, j->larg = pull_up_subqueries(root, j->larg,
true); true);
j->rarg = pull_up_subqueries(parse, j->rarg, j->rarg = pull_up_subqueries(root, j->rarg,
below_outer_join); below_outer_join);
break; break;
case JOIN_UNION: case JOIN_UNION:
...@@ -555,7 +570,7 @@ resolvenew_in_jointree(Node *jtnode, int varno, ...@@ -555,7 +570,7 @@ resolvenew_in_jointree(Node *jtnode, int varno,
* alias-var expansion). * alias-var expansion).
*/ */
void void
reduce_outer_joins(Query *parse) reduce_outer_joins(PlannerInfo *root)
{ {
reduce_outer_joins_state *state; reduce_outer_joins_state *state;
...@@ -569,13 +584,14 @@ reduce_outer_joins(Query *parse) ...@@ -569,13 +584,14 @@ reduce_outer_joins(Query *parse)
* clause. The second pass examines qual clauses and changes join * clause. The second pass examines qual clauses and changes join
* types as it descends the tree. * types as it descends the tree.
*/ */
state = reduce_outer_joins_pass1((Node *) parse->jointree); state = reduce_outer_joins_pass1((Node *) root->parse->jointree);
/* planner.c shouldn't have called me if no outer joins */ /* planner.c shouldn't have called me if no outer joins */
if (state == NULL || !state->contains_outer) if (state == NULL || !state->contains_outer)
elog(ERROR, "so where are the outer joins?"); elog(ERROR, "so where are the outer joins?");
reduce_outer_joins_pass2((Node *) parse->jointree, state, parse, NULL); reduce_outer_joins_pass2((Node *) root->parse->jointree,
state, root, NULL);
} }
/* /*
...@@ -650,13 +666,13 @@ reduce_outer_joins_pass1(Node *jtnode) ...@@ -650,13 +666,13 @@ reduce_outer_joins_pass1(Node *jtnode)
* *
* jtnode: current jointree node * jtnode: current jointree node
* state: state data collected by phase 1 for this node * state: state data collected by phase 1 for this node
* parse: toplevel Query * root: toplevel planner state
* nonnullable_rels: set of base relids forced non-null by upper quals * nonnullable_rels: set of base relids forced non-null by upper quals
*/ */
static void static void
reduce_outer_joins_pass2(Node *jtnode, reduce_outer_joins_pass2(Node *jtnode,
reduce_outer_joins_state *state, reduce_outer_joins_state *state,
Query *parse, PlannerInfo *root,
Relids nonnullable_rels) Relids nonnullable_rels)
{ {
/* /*
...@@ -685,7 +701,7 @@ reduce_outer_joins_pass2(Node *jtnode, ...@@ -685,7 +701,7 @@ reduce_outer_joins_pass2(Node *jtnode,
reduce_outer_joins_state *sub_state = lfirst(s); reduce_outer_joins_state *sub_state = lfirst(s);
if (sub_state->contains_outer) if (sub_state->contains_outer)
reduce_outer_joins_pass2(lfirst(l), sub_state, parse, reduce_outer_joins_pass2(lfirst(l), sub_state, root,
pass_nonnullable); pass_nonnullable);
} }
bms_free(pass_nonnullable); bms_free(pass_nonnullable);
...@@ -729,7 +745,7 @@ reduce_outer_joins_pass2(Node *jtnode, ...@@ -729,7 +745,7 @@ reduce_outer_joins_pass2(Node *jtnode,
if (jointype != j->jointype) if (jointype != j->jointype)
{ {
/* apply the change to both jointree node and RTE */ /* apply the change to both jointree node and RTE */
RangeTblEntry *rte = rt_fetch(rtindex, parse->rtable); RangeTblEntry *rte = rt_fetch(rtindex, root->parse->rtable);
Assert(rte->rtekind == RTE_JOIN); Assert(rte->rtekind == RTE_JOIN);
Assert(rte->jointype == j->jointype); Assert(rte->jointype == j->jointype);
...@@ -767,7 +783,7 @@ reduce_outer_joins_pass2(Node *jtnode, ...@@ -767,7 +783,7 @@ reduce_outer_joins_pass2(Node *jtnode,
pass_nonnullable = local_nonnullable; pass_nonnullable = local_nonnullable;
else else
pass_nonnullable = nonnullable_rels; pass_nonnullable = nonnullable_rels;
reduce_outer_joins_pass2(j->larg, left_state, parse, reduce_outer_joins_pass2(j->larg, left_state, root,
pass_nonnullable); pass_nonnullable);
} }
if (right_state->contains_outer) if (right_state->contains_outer)
...@@ -776,7 +792,7 @@ reduce_outer_joins_pass2(Node *jtnode, ...@@ -776,7 +792,7 @@ reduce_outer_joins_pass2(Node *jtnode,
pass_nonnullable = local_nonnullable; pass_nonnullable = local_nonnullable;
else else
pass_nonnullable = nonnullable_rels; pass_nonnullable = nonnullable_rels;
reduce_outer_joins_pass2(j->rarg, right_state, parse, reduce_outer_joins_pass2(j->rarg, right_state, root,
pass_nonnullable); pass_nonnullable);
} }
bms_free(local_nonnullable); bms_free(local_nonnullable);
...@@ -909,7 +925,7 @@ find_nonnullable_rels(Node *node, bool top_level) ...@@ -909,7 +925,7 @@ find_nonnullable_rels(Node *node, bool top_level)
* work reliably --- see comments for pull_up_subqueries(). * work reliably --- see comments for pull_up_subqueries().
*/ */
Node * Node *
simplify_jointree(Query *parse, Node *jtnode) simplify_jointree(PlannerInfo *root, Node *jtnode)
{ {
if (jtnode == NULL) if (jtnode == NULL)
return NULL; return NULL;
...@@ -931,7 +947,7 @@ simplify_jointree(Query *parse, Node *jtnode) ...@@ -931,7 +947,7 @@ simplify_jointree(Query *parse, Node *jtnode)
children_remaining--; children_remaining--;
/* Recursively simplify this child... */ /* Recursively simplify this child... */
child = simplify_jointree(parse, child); child = simplify_jointree(root, child);
/* Now, is it a FromExpr? */ /* Now, is it a FromExpr? */
if (child && IsA(child, FromExpr)) if (child && IsA(child, FromExpr))
{ {
...@@ -972,8 +988,8 @@ simplify_jointree(Query *parse, Node *jtnode) ...@@ -972,8 +988,8 @@ simplify_jointree(Query *parse, Node *jtnode)
JoinExpr *j = (JoinExpr *) jtnode; JoinExpr *j = (JoinExpr *) jtnode;
/* Recursively simplify the children... */ /* Recursively simplify the children... */
j->larg = simplify_jointree(parse, j->larg); j->larg = simplify_jointree(root, j->larg);
j->rarg = simplify_jointree(parse, j->rarg); j->rarg = simplify_jointree(root, j->rarg);
/* /*
* If it is an outer join, we must not flatten it. An inner join * If it is an outer join, we must not flatten it. An inner join
...@@ -1115,11 +1131,12 @@ get_relids_in_jointree(Node *jtnode) ...@@ -1115,11 +1131,12 @@ get_relids_in_jointree(Node *jtnode)
* since that may eliminate join nodes from the jointree. * since that may eliminate join nodes from the jointree.
*/ */
Relids Relids
get_relids_for_join(Query *parse, int joinrelid) get_relids_for_join(PlannerInfo *root, int joinrelid)
{ {
Node *jtnode; Node *jtnode;
jtnode = find_jointree_node_for_rel((Node *) parse->jointree, joinrelid); jtnode = find_jointree_node_for_rel((Node *) root->parse->jointree,
joinrelid);
if (!jtnode) if (!jtnode)
elog(ERROR, "could not find join node %d", joinrelid); elog(ERROR, "could not find join node %d", joinrelid);
return get_relids_in_jointree(jtnode); return get_relids_in_jointree(jtnode);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.76 2005/05/23 03:01:13 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.77 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -43,8 +43,9 @@ static List *expand_targetlist(List *tlist, int command_type, ...@@ -43,8 +43,9 @@ static List *expand_targetlist(List *tlist, int command_type,
* Returns the new targetlist. * Returns the new targetlist.
*/ */
List * List *
preprocess_targetlist(Query *parse, List *tlist) preprocess_targetlist(PlannerInfo *root, List *tlist)
{ {
Query *parse = root->parse;
int result_relation = parse->resultRelation; int result_relation = parse->resultRelation;
List *range_table = parse->rtable; List *range_table = parse->rtable;
CmdType command_type = parse->commandType; CmdType command_type = parse->commandType;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.121 2005/05/22 22:30:19 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepunion.c,v 1.122 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -49,15 +49,15 @@ typedef struct ...@@ -49,15 +49,15 @@ typedef struct
char *new_rel_name; char *new_rel_name;
} adjust_inherited_attrs_context; } adjust_inherited_attrs_context;
static Plan *recurse_set_operations(Node *setOp, Query *parse, static Plan *recurse_set_operations(Node *setOp, PlannerInfo *root,
List *colTypes, bool junkOK, List *colTypes, bool junkOK,
int flag, List *refnames_tlist, int flag, List *refnames_tlist,
List **sortClauses); List **sortClauses);
static Plan *generate_union_plan(SetOperationStmt *op, Query *parse, static Plan *generate_union_plan(SetOperationStmt *op, PlannerInfo *root,
List *refnames_tlist, List **sortClauses); List *refnames_tlist, List **sortClauses);
static Plan *generate_nonunion_plan(SetOperationStmt *op, Query *parse, static Plan *generate_nonunion_plan(SetOperationStmt *op, PlannerInfo *root,
List *refnames_tlist, List **sortClauses); List *refnames_tlist, List **sortClauses);
static List *recurse_union_children(Node *setOp, Query *parse, static List *recurse_union_children(Node *setOp, PlannerInfo *root,
SetOperationStmt *top_union, SetOperationStmt *top_union,
List *refnames_tlist); List *refnames_tlist);
static List *generate_setop_tlist(List *colTypes, int flag, static List *generate_setop_tlist(List *colTypes, int flag,
...@@ -82,15 +82,16 @@ static List *adjust_inherited_tlist(List *tlist, ...@@ -82,15 +82,16 @@ static List *adjust_inherited_tlist(List *tlist,
* Plans the queries for a tree of set operations (UNION/INTERSECT/EXCEPT) * Plans the queries for a tree of set operations (UNION/INTERSECT/EXCEPT)
* *
* This routine only deals with the setOperations tree of the given query. * This routine only deals with the setOperations tree of the given query.
* Any top-level ORDER BY requested in parse->sortClause will be added * Any top-level ORDER BY requested in root->parse->sortClause will be added
* when we return to grouping_planner. * when we return to grouping_planner.
* *
* *sortClauses is an output argument: it is set to a list of SortClauses * *sortClauses is an output argument: it is set to a list of SortClauses
* representing the result ordering of the topmost set operation. * representing the result ordering of the topmost set operation.
*/ */
Plan * Plan *
plan_set_operations(Query *parse, List **sortClauses) plan_set_operations(PlannerInfo *root, List **sortClauses)
{ {
Query *parse = root->parse;
SetOperationStmt *topop = (SetOperationStmt *) parse->setOperations; SetOperationStmt *topop = (SetOperationStmt *) parse->setOperations;
Node *node; Node *node;
Query *leftmostQuery; Query *leftmostQuery;
...@@ -123,7 +124,7 @@ plan_set_operations(Query *parse, List **sortClauses) ...@@ -123,7 +124,7 @@ plan_set_operations(Query *parse, List **sortClauses)
* output from the top-level node, plus possibly resjunk working * output from the top-level node, plus possibly resjunk working
* columns (we can rely on upper-level nodes to deal with that). * columns (we can rely on upper-level nodes to deal with that).
*/ */
return recurse_set_operations((Node *) topop, parse, return recurse_set_operations((Node *) topop, root,
topop->colTypes, true, -1, topop->colTypes, true, -1,
leftmostQuery->targetList, leftmostQuery->targetList,
sortClauses); sortClauses);
...@@ -140,7 +141,7 @@ plan_set_operations(Query *parse, List **sortClauses) ...@@ -140,7 +141,7 @@ plan_set_operations(Query *parse, List **sortClauses)
* *sortClauses: receives list of SortClauses for result plan, if any * *sortClauses: receives list of SortClauses for result plan, if any
*/ */
static Plan * static Plan *
recurse_set_operations(Node *setOp, Query *parse, recurse_set_operations(Node *setOp, PlannerInfo *root,
List *colTypes, bool junkOK, List *colTypes, bool junkOK,
int flag, List *refnames_tlist, int flag, List *refnames_tlist,
List **sortClauses) List **sortClauses)
...@@ -148,7 +149,7 @@ recurse_set_operations(Node *setOp, Query *parse, ...@@ -148,7 +149,7 @@ recurse_set_operations(Node *setOp, Query *parse,
if (IsA(setOp, RangeTblRef)) if (IsA(setOp, RangeTblRef))
{ {
RangeTblRef *rtr = (RangeTblRef *) setOp; RangeTblRef *rtr = (RangeTblRef *) setOp;
RangeTblEntry *rte = rt_fetch(rtr->rtindex, parse->rtable); RangeTblEntry *rte = rt_fetch(rtr->rtindex, root->parse->rtable);
Query *subquery = rte->subquery; Query *subquery = rte->subquery;
Plan *subplan, Plan *subplan,
*plan; *plan;
...@@ -158,7 +159,7 @@ recurse_set_operations(Node *setOp, Query *parse, ...@@ -158,7 +159,7 @@ recurse_set_operations(Node *setOp, Query *parse,
/* /*
* Generate plan for primitive subquery * Generate plan for primitive subquery
*/ */
subplan = subquery_planner(subquery, 0.0 /* default case */ ); subplan = subquery_planner(subquery, 0.0 /* default case */, NULL);
/* /*
* Add a SubqueryScan with the caller-requested targetlist * Add a SubqueryScan with the caller-requested targetlist
...@@ -188,10 +189,10 @@ recurse_set_operations(Node *setOp, Query *parse, ...@@ -188,10 +189,10 @@ recurse_set_operations(Node *setOp, Query *parse,
/* UNIONs are much different from INTERSECT/EXCEPT */ /* UNIONs are much different from INTERSECT/EXCEPT */
if (op->op == SETOP_UNION) if (op->op == SETOP_UNION)
plan = generate_union_plan(op, parse, refnames_tlist, plan = generate_union_plan(op, root, refnames_tlist,
sortClauses); sortClauses);
else else
plan = generate_nonunion_plan(op, parse, refnames_tlist, plan = generate_nonunion_plan(op, root, refnames_tlist,
sortClauses); sortClauses);
/* /*
...@@ -233,7 +234,7 @@ recurse_set_operations(Node *setOp, Query *parse, ...@@ -233,7 +234,7 @@ recurse_set_operations(Node *setOp, Query *parse,
* Generate plan for a UNION or UNION ALL node * Generate plan for a UNION or UNION ALL node
*/ */
static Plan * static Plan *
generate_union_plan(SetOperationStmt *op, Query *parse, generate_union_plan(SetOperationStmt *op, PlannerInfo *root,
List *refnames_tlist, List *refnames_tlist,
List **sortClauses) List **sortClauses)
{ {
...@@ -247,9 +248,9 @@ generate_union_plan(SetOperationStmt *op, Query *parse, ...@@ -247,9 +248,9 @@ generate_union_plan(SetOperationStmt *op, Query *parse,
* generate only one Append and Sort for the lot. Recurse to find * generate only one Append and Sort for the lot. Recurse to find
* such nodes and compute their children's plans. * such nodes and compute their children's plans.
*/ */
planlist = list_concat(recurse_union_children(op->larg, parse, planlist = list_concat(recurse_union_children(op->larg, root,
op, refnames_tlist), op, refnames_tlist),
recurse_union_children(op->rarg, parse, recurse_union_children(op->rarg, root,
op, refnames_tlist)); op, refnames_tlist));
/* /*
...@@ -278,7 +279,7 @@ generate_union_plan(SetOperationStmt *op, Query *parse, ...@@ -278,7 +279,7 @@ generate_union_plan(SetOperationStmt *op, Query *parse,
sortList = addAllTargetsToSortList(NULL, NIL, tlist, false); sortList = addAllTargetsToSortList(NULL, NIL, tlist, false);
if (sortList) if (sortList)
{ {
plan = (Plan *) make_sort_from_sortclauses(parse, sortList, plan); plan = (Plan *) make_sort_from_sortclauses(root, sortList, plan);
plan = (Plan *) make_unique(plan, sortList); plan = (Plan *) make_unique(plan, sortList);
} }
*sortClauses = sortList; *sortClauses = sortList;
...@@ -293,7 +294,7 @@ generate_union_plan(SetOperationStmt *op, Query *parse, ...@@ -293,7 +294,7 @@ generate_union_plan(SetOperationStmt *op, Query *parse,
* Generate plan for an INTERSECT, INTERSECT ALL, EXCEPT, or EXCEPT ALL node * Generate plan for an INTERSECT, INTERSECT ALL, EXCEPT, or EXCEPT ALL node
*/ */
static Plan * static Plan *
generate_nonunion_plan(SetOperationStmt *op, Query *parse, generate_nonunion_plan(SetOperationStmt *op, PlannerInfo *root,
List *refnames_tlist, List *refnames_tlist,
List **sortClauses) List **sortClauses)
{ {
...@@ -307,11 +308,11 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse, ...@@ -307,11 +308,11 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
SetOpCmd cmd; SetOpCmd cmd;
/* Recurse on children, ensuring their outputs are marked */ /* Recurse on children, ensuring their outputs are marked */
lplan = recurse_set_operations(op->larg, parse, lplan = recurse_set_operations(op->larg, root,
op->colTypes, false, 0, op->colTypes, false, 0,
refnames_tlist, refnames_tlist,
&child_sortclauses); &child_sortclauses);
rplan = recurse_set_operations(op->rarg, parse, rplan = recurse_set_operations(op->rarg, root,
op->colTypes, false, 1, op->colTypes, false, 1,
refnames_tlist, refnames_tlist,
&child_sortclauses); &child_sortclauses);
...@@ -346,7 +347,7 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse, ...@@ -346,7 +347,7 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
return plan; return plan;
} }
plan = (Plan *) make_sort_from_sortclauses(parse, sortList, plan); plan = (Plan *) make_sort_from_sortclauses(root, sortList, plan);
switch (op->op) switch (op->op)
{ {
case SETOP_INTERSECT: case SETOP_INTERSECT:
...@@ -375,7 +376,7 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse, ...@@ -375,7 +376,7 @@ generate_nonunion_plan(SetOperationStmt *op, Query *parse,
* output rows will be lost anyway. * output rows will be lost anyway.
*/ */
static List * static List *
recurse_union_children(Node *setOp, Query *parse, recurse_union_children(Node *setOp, PlannerInfo *root,
SetOperationStmt *top_union, SetOperationStmt *top_union,
List *refnames_tlist) List *refnames_tlist)
{ {
...@@ -390,10 +391,10 @@ recurse_union_children(Node *setOp, Query *parse, ...@@ -390,10 +391,10 @@ recurse_union_children(Node *setOp, Query *parse,
equal(op->colTypes, top_union->colTypes)) equal(op->colTypes, top_union->colTypes))
{ {
/* Same UNION, so fold children into parent's subplan list */ /* Same UNION, so fold children into parent's subplan list */
return list_concat(recurse_union_children(op->larg, parse, return list_concat(recurse_union_children(op->larg, root,
top_union, top_union,
refnames_tlist), refnames_tlist),
recurse_union_children(op->rarg, parse, recurse_union_children(op->rarg, root,
top_union, top_union,
refnames_tlist)); refnames_tlist));
} }
...@@ -409,7 +410,7 @@ recurse_union_children(Node *setOp, Query *parse, ...@@ -409,7 +410,7 @@ recurse_union_children(Node *setOp, Query *parse,
* we have an EXCEPT or INTERSECT as child, else there won't be * we have an EXCEPT or INTERSECT as child, else there won't be
* resjunk anyway. * resjunk anyway.
*/ */
return list_make1(recurse_set_operations(setOp, parse, return list_make1(recurse_set_operations(setOp, root,
top_union->colTypes, false, top_union->colTypes, false,
-1, refnames_tlist, -1, refnames_tlist,
&child_sortclauses)); &child_sortclauses));
...@@ -724,8 +725,9 @@ find_all_inheritors(Oid parentrel) ...@@ -724,8 +725,9 @@ find_all_inheritors(Oid parentrel)
* trying to avoid. * trying to avoid.
*/ */
List * List *
expand_inherited_rtentry(Query *parse, Index rti) expand_inherited_rtentry(PlannerInfo *root, Index rti)
{ {
Query *parse = root->parse;
RangeTblEntry *rte = rt_fetch(rti, parse->rtable); RangeTblEntry *rte = rt_fetch(rti, parse->rtable);
Oid parentOID; Oid parentOID;
List *inhOIDs; List *inhOIDs;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.197 2005/05/22 22:30:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.198 2005/06/05 22:32:56 tgl Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -3040,8 +3040,6 @@ query_tree_walker(Query *query, ...@@ -3040,8 +3040,6 @@ query_tree_walker(Query *query,
return true; return true;
if (walker(query->limitCount, context)) if (walker(query->limitCount, context))
return true; return true;
if (walker(query->in_info_list, context))
return true;
if (range_table_walker(query->rtable, walker, context, flags)) if (range_table_walker(query->rtable, walker, context, flags))
return true; return true;
return false; return false;
...@@ -3564,7 +3562,6 @@ query_tree_mutator(Query *query, ...@@ -3564,7 +3562,6 @@ query_tree_mutator(Query *query,
MUTATE(query->havingQual, query->havingQual, Node *); MUTATE(query->havingQual, query->havingQual, Node *);
MUTATE(query->limitOffset, query->limitOffset, Node *); MUTATE(query->limitOffset, query->limitOffset, Node *);
MUTATE(query->limitCount, query->limitCount, Node *); MUTATE(query->limitCount, query->limitCount, Node *);
MUTATE(query->in_info_list, query->in_info_list, List *);
query->rtable = range_table_mutator(query->rtable, query->rtable = range_table_mutator(query->rtable,
mutator, context, flags); mutator, context, flags);
return query; return query;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/joininfo.c,v 1.41 2004/12/31 22:00:23 pgsql Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/joininfo.c,v 1.42 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -82,7 +82,7 @@ make_joininfo_node(RelOptInfo *this_rel, Relids join_relids) ...@@ -82,7 +82,7 @@ make_joininfo_node(RelOptInfo *this_rel, Relids join_relids)
* (there must be more than one) * (there must be more than one)
*/ */
void void
add_join_clause_to_rels(Query *root, add_join_clause_to_rels(PlannerInfo *root,
RestrictInfo *restrictinfo, RestrictInfo *restrictinfo,
Relids join_relids) Relids join_relids)
{ {
...@@ -131,7 +131,7 @@ add_join_clause_to_rels(Query *root, ...@@ -131,7 +131,7 @@ add_join_clause_to_rels(Query *root,
* (there must be more than one) * (there must be more than one)
*/ */
void void
remove_join_clause_from_rels(Query *root, remove_join_clause_from_rels(PlannerInfo *root,
RestrictInfo *restrictinfo, RestrictInfo *restrictinfo,
Relids join_relids) Relids join_relids)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.121 2005/06/03 19:00:12 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.122 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -415,7 +415,7 @@ add_path(RelOptInfo *parent_rel, Path *new_path) ...@@ -415,7 +415,7 @@ add_path(RelOptInfo *parent_rel, Path *new_path)
* pathnode. * pathnode.
*/ */
Path * Path *
create_seqscan_path(Query *root, RelOptInfo *rel) create_seqscan_path(PlannerInfo *root, RelOptInfo *rel)
{ {
Path *pathnode = makeNode(Path); Path *pathnode = makeNode(Path);
...@@ -445,7 +445,7 @@ create_seqscan_path(Query *root, RelOptInfo *rel) ...@@ -445,7 +445,7 @@ create_seqscan_path(Query *root, RelOptInfo *rel)
* Returns the new path node. * Returns the new path node.
*/ */
IndexPath * IndexPath *
create_index_path(Query *root, create_index_path(PlannerInfo *root,
IndexOptInfo *index, IndexOptInfo *index,
List *clause_groups, List *clause_groups,
List *pathkeys, List *pathkeys,
...@@ -537,7 +537,7 @@ create_index_path(Query *root, ...@@ -537,7 +537,7 @@ create_index_path(Query *root,
* 'bitmapqual' is a tree of IndexPath, BitmapAndPath, and BitmapOrPath nodes. * 'bitmapqual' is a tree of IndexPath, BitmapAndPath, and BitmapOrPath nodes.
*/ */
BitmapHeapPath * BitmapHeapPath *
create_bitmap_heap_path(Query *root, create_bitmap_heap_path(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
Path *bitmapqual, Path *bitmapqual,
bool isjoininner) bool isjoininner)
...@@ -590,7 +590,7 @@ create_bitmap_heap_path(Query *root, ...@@ -590,7 +590,7 @@ create_bitmap_heap_path(Query *root,
* Creates a path node representing a BitmapAnd. * Creates a path node representing a BitmapAnd.
*/ */
BitmapAndPath * BitmapAndPath *
create_bitmap_and_path(Query *root, create_bitmap_and_path(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
List *bitmapquals) List *bitmapquals)
{ {
...@@ -613,7 +613,7 @@ create_bitmap_and_path(Query *root, ...@@ -613,7 +613,7 @@ create_bitmap_and_path(Query *root,
* Creates a path node representing a BitmapOr. * Creates a path node representing a BitmapOr.
*/ */
BitmapOrPath * BitmapOrPath *
create_bitmap_or_path(Query *root, create_bitmap_or_path(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
List *bitmapquals) List *bitmapquals)
{ {
...@@ -637,7 +637,7 @@ create_bitmap_or_path(Query *root, ...@@ -637,7 +637,7 @@ create_bitmap_or_path(Query *root,
* pathnode. * pathnode.
*/ */
TidPath * TidPath *
create_tidscan_path(Query *root, RelOptInfo *rel, List *tideval) create_tidscan_path(PlannerInfo *root, RelOptInfo *rel, List *tideval)
{ {
TidPath *pathnode = makeNode(TidPath); TidPath *pathnode = makeNode(TidPath);
...@@ -759,7 +759,7 @@ create_material_path(RelOptInfo *rel, Path *subpath) ...@@ -759,7 +759,7 @@ create_material_path(RelOptInfo *rel, Path *subpath)
* for the rel). So we cache the result. * for the rel). So we cache the result.
*/ */
UniquePath * UniquePath *
create_unique_path(Query *root, RelOptInfo *rel, Path *subpath) create_unique_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath)
{ {
UniquePath *pathnode; UniquePath *pathnode;
Path sort_path; /* dummy for result of cost_sort */ Path sort_path; /* dummy for result of cost_sort */
...@@ -805,7 +805,7 @@ create_unique_path(Query *root, RelOptInfo *rel, Path *subpath) ...@@ -805,7 +805,7 @@ create_unique_path(Query *root, RelOptInfo *rel, Path *subpath)
*/ */
if (rel->rtekind == RTE_SUBQUERY) if (rel->rtekind == RTE_SUBQUERY)
{ {
RangeTblEntry *rte = rt_fetch(rel->relid, root->rtable); RangeTblEntry *rte = rt_fetch(rel->relid, root->parse->rtable);
if (is_distinct_query(rte->subquery)) if (is_distinct_query(rte->subquery))
{ {
...@@ -1029,7 +1029,7 @@ create_subqueryscan_path(RelOptInfo *rel, List *pathkeys) ...@@ -1029,7 +1029,7 @@ create_subqueryscan_path(RelOptInfo *rel, List *pathkeys)
* returning the pathnode. * returning the pathnode.
*/ */
Path * Path *
create_functionscan_path(Query *root, RelOptInfo *rel) create_functionscan_path(PlannerInfo *root, RelOptInfo *rel)
{ {
Path *pathnode = makeNode(Path); Path *pathnode = makeNode(Path);
...@@ -1057,7 +1057,7 @@ create_functionscan_path(Query *root, RelOptInfo *rel) ...@@ -1057,7 +1057,7 @@ create_functionscan_path(Query *root, RelOptInfo *rel)
* Returns the resulting path node. * Returns the resulting path node.
*/ */
NestPath * NestPath *
create_nestloop_path(Query *root, create_nestloop_path(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
JoinType jointype, JoinType jointype,
Path *outer_path, Path *outer_path,
...@@ -1097,7 +1097,7 @@ create_nestloop_path(Query *root, ...@@ -1097,7 +1097,7 @@ create_nestloop_path(Query *root,
* 'innersortkeys' are the sort varkeys for the inner relation * 'innersortkeys' are the sort varkeys for the inner relation
*/ */
MergePath * MergePath *
create_mergejoin_path(Query *root, create_mergejoin_path(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
JoinType jointype, JoinType jointype,
Path *outer_path, Path *outer_path,
...@@ -1166,7 +1166,7 @@ create_mergejoin_path(Query *root, ...@@ -1166,7 +1166,7 @@ create_mergejoin_path(Query *root,
* (this should be a subset of the restrict_clauses list) * (this should be a subset of the restrict_clauses list)
*/ */
HashPath * HashPath *
create_hashjoin_path(Query *root, create_hashjoin_path(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
JoinType jointype, JoinType jointype,
Path *outer_path, Path *outer_path,
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.110 2005/06/04 19:19:42 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.111 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -379,11 +379,11 @@ estimate_rel_size(Relation rel, int32 *attr_widths, ...@@ -379,11 +379,11 @@ estimate_rel_size(Relation rel, int32 *attr_widths,
* nodes. * nodes.
*/ */
List * List *
build_physical_tlist(Query *root, RelOptInfo *rel) build_physical_tlist(PlannerInfo *root, RelOptInfo *rel)
{ {
List *tlist = NIL; List *tlist = NIL;
Index varno = rel->relid; Index varno = rel->relid;
RangeTblEntry *rte = rt_fetch(varno, root->rtable); RangeTblEntry *rte = rt_fetch(varno, root->parse->rtable);
Relation relation; Relation relation;
Query *subquery; Query *subquery;
Var *var; Var *var;
...@@ -494,7 +494,7 @@ build_physical_tlist(Query *root, RelOptInfo *rel) ...@@ -494,7 +494,7 @@ build_physical_tlist(Query *root, RelOptInfo *rel)
* See clause_selectivity() for the meaning of the additional parameters. * See clause_selectivity() for the meaning of the additional parameters.
*/ */
Selectivity Selectivity
restriction_selectivity(Query *root, restriction_selectivity(PlannerInfo *root,
Oid operator, Oid operator,
List *args, List *args,
int varRelid) int varRelid)
...@@ -529,7 +529,7 @@ restriction_selectivity(Query *root, ...@@ -529,7 +529,7 @@ restriction_selectivity(Query *root,
* operator relation, by calling the function manager. * operator relation, by calling the function manager.
*/ */
Selectivity Selectivity
join_selectivity(Query *root, join_selectivity(PlannerInfo *root,
Oid operator, Oid operator,
List *args, List *args,
JoinType jointype) JoinType jointype)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.66 2005/05/23 03:01:14 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/relnode.c,v 1.67 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
#include "parser/parsetree.h" #include "parser/parsetree.h"
static RelOptInfo *make_reloptinfo(Query *root, int relid, static RelOptInfo *make_reloptinfo(PlannerInfo *root, int relid,
RelOptKind reloptkind); RelOptKind reloptkind);
static void build_joinrel_tlist(Query *root, RelOptInfo *joinrel); static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel);
static List *build_joinrel_restrictlist(Query *root, static List *build_joinrel_restrictlist(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
RelOptInfo *outer_rel, RelOptInfo *outer_rel,
RelOptInfo *inner_rel, RelOptInfo *inner_rel,
...@@ -46,7 +46,7 @@ static void subbuild_joinrel_joinlist(RelOptInfo *joinrel, ...@@ -46,7 +46,7 @@ static void subbuild_joinrel_joinlist(RelOptInfo *joinrel,
* base_rel_list. * base_rel_list.
*/ */
void void
build_base_rel(Query *root, int relid) build_base_rel(PlannerInfo *root, int relid)
{ {
ListCell *l; ListCell *l;
RelOptInfo *rel; RelOptInfo *rel;
...@@ -81,7 +81,7 @@ build_base_rel(Query *root, int relid) ...@@ -81,7 +81,7 @@ build_base_rel(Query *root, int relid)
* base relations except that they live in a different list. * base relations except that they live in a different list.
*/ */
RelOptInfo * RelOptInfo *
build_other_rel(Query *root, int relid) build_other_rel(PlannerInfo *root, int relid)
{ {
ListCell *l; ListCell *l;
RelOptInfo *rel; RelOptInfo *rel;
...@@ -119,10 +119,10 @@ build_other_rel(Query *root, int relid) ...@@ -119,10 +119,10 @@ build_other_rel(Query *root, int relid)
* Common code for build_base_rel and build_other_rel. * Common code for build_base_rel and build_other_rel.
*/ */
static RelOptInfo * static RelOptInfo *
make_reloptinfo(Query *root, int relid, RelOptKind reloptkind) make_reloptinfo(PlannerInfo *root, int relid, RelOptKind reloptkind)
{ {
RelOptInfo *rel = makeNode(RelOptInfo); RelOptInfo *rel = makeNode(RelOptInfo);
RangeTblEntry *rte = rt_fetch(relid, root->rtable); RangeTblEntry *rte = rt_fetch(relid, root->parse->rtable);
rel->reloptkind = reloptkind; rel->reloptkind = reloptkind;
rel->relids = bms_make_singleton(relid); rel->relids = bms_make_singleton(relid);
...@@ -181,7 +181,7 @@ make_reloptinfo(Query *root, int relid, RelOptKind reloptkind) ...@@ -181,7 +181,7 @@ make_reloptinfo(Query *root, int relid, RelOptKind reloptkind)
* (since we'd have no idea which list to add it to). * (since we'd have no idea which list to add it to).
*/ */
RelOptInfo * RelOptInfo *
find_base_rel(Query *root, int relid) find_base_rel(PlannerInfo *root, int relid)
{ {
ListCell *l; ListCell *l;
RelOptInfo *rel; RelOptInfo *rel;
...@@ -211,7 +211,7 @@ find_base_rel(Query *root, int relid) ...@@ -211,7 +211,7 @@ find_base_rel(Query *root, int relid)
* or NULL if none exists. This is for join relations. * or NULL if none exists. This is for join relations.
*/ */
RelOptInfo * RelOptInfo *
find_join_rel(Query *root, Relids relids) find_join_rel(PlannerInfo *root, Relids relids)
{ {
ListCell *l; ListCell *l;
...@@ -243,7 +243,7 @@ find_join_rel(Query *root, Relids relids) ...@@ -243,7 +243,7 @@ find_join_rel(Query *root, Relids relids)
* duplicated calculation of the restrictlist... * duplicated calculation of the restrictlist...
*/ */
RelOptInfo * RelOptInfo *
build_join_rel(Query *root, build_join_rel(PlannerInfo *root,
Relids joinrelids, Relids joinrelids,
RelOptInfo *outer_rel, RelOptInfo *outer_rel,
RelOptInfo *inner_rel, RelOptInfo *inner_rel,
...@@ -356,7 +356,7 @@ build_join_rel(Query *root, ...@@ -356,7 +356,7 @@ build_join_rel(Query *root,
* of data that was cached at the baserel level by set_rel_width(). * of data that was cached at the baserel level by set_rel_width().
*/ */
static void static void
build_joinrel_tlist(Query *root, RelOptInfo *joinrel) build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel)
{ {
Relids relids = joinrel->relids; Relids relids = joinrel->relids;
ListCell *rels; ListCell *rels;
...@@ -433,7 +433,7 @@ build_joinrel_tlist(Query *root, RelOptInfo *joinrel) ...@@ -433,7 +433,7 @@ build_joinrel_tlist(Query *root, RelOptInfo *joinrel)
* the original nodes in the lists made for the join relation. * the original nodes in the lists made for the join relation.
*/ */
static List * static List *
build_joinrel_restrictlist(Query *root, build_joinrel_restrictlist(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
RelOptInfo *outer_rel, RelOptInfo *outer_rel,
RelOptInfo *inner_rel, RelOptInfo *inner_rel,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.35 2005/04/25 02:14:47 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.36 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -28,7 +28,7 @@ static RestrictInfo *make_restrictinfo_internal(Expr *clause, ...@@ -28,7 +28,7 @@ static RestrictInfo *make_restrictinfo_internal(Expr *clause,
static Expr *make_sub_restrictinfos(Expr *clause, static Expr *make_sub_restrictinfos(Expr *clause,
bool is_pushed_down, bool is_pushed_down,
bool valid_everywhere); bool valid_everywhere);
static RestrictInfo *join_clause_is_redundant(Query *root, static RestrictInfo *join_clause_is_redundant(PlannerInfo *root,
RestrictInfo *rinfo, RestrictInfo *rinfo,
List *reference_list, List *reference_list,
bool isouterjoin); bool isouterjoin);
...@@ -354,7 +354,7 @@ get_actual_join_clauses(List *restrictinfo_list, ...@@ -354,7 +354,7 @@ get_actual_join_clauses(List *restrictinfo_list,
* as were in the input. * as were in the input.
*/ */
List * List *
remove_redundant_join_clauses(Query *root, List *restrictinfo_list, remove_redundant_join_clauses(PlannerInfo *root, List *restrictinfo_list,
bool isouterjoin) bool isouterjoin)
{ {
List *result = NIL; List *result = NIL;
...@@ -415,7 +415,7 @@ remove_redundant_join_clauses(Query *root, List *restrictinfo_list, ...@@ -415,7 +415,7 @@ remove_redundant_join_clauses(Query *root, List *restrictinfo_list,
* for local redundancies, so we don't check again. * for local redundancies, so we don't check again.
*/ */
List * List *
select_nonredundant_join_clauses(Query *root, select_nonredundant_join_clauses(PlannerInfo *root,
List *restrictinfo_list, List *restrictinfo_list,
List *reference_list, List *reference_list,
bool isouterjoin) bool isouterjoin)
...@@ -467,7 +467,7 @@ select_nonredundant_join_clauses(Query *root, ...@@ -467,7 +467,7 @@ select_nonredundant_join_clauses(Query *root,
* joined rows after addition of null fill rows, and the other doesn't. * joined rows after addition of null fill rows, and the other doesn't.
*/ */
static RestrictInfo * static RestrictInfo *
join_clause_is_redundant(Query *root, join_clause_is_redundant(PlannerInfo *root,
RestrictInfo *rinfo, RestrictInfo *rinfo,
List *reference_list, List *reference_list,
bool isouterjoin) bool isouterjoin)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.64 2005/06/03 23:05:28 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.65 2005/06/05 22:32:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -49,7 +49,7 @@ typedef struct ...@@ -49,7 +49,7 @@ typedef struct
typedef struct typedef struct
{ {
Query *root; PlannerInfo *root;
int sublevels_up; int sublevels_up;
} flatten_join_alias_vars_context; } flatten_join_alias_vars_context;
...@@ -66,7 +66,7 @@ static bool pull_var_clause_walker(Node *node, ...@@ -66,7 +66,7 @@ static bool pull_var_clause_walker(Node *node,
pull_var_clause_context *context); pull_var_clause_context *context);
static Node *flatten_join_alias_vars_mutator(Node *node, static Node *flatten_join_alias_vars_mutator(Node *node,
flatten_join_alias_vars_context *context); flatten_join_alias_vars_context *context);
static Relids alias_relid_set(Query *root, Relids relids); static Relids alias_relid_set(PlannerInfo *root, Relids relids);
/* /*
...@@ -482,7 +482,7 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context) ...@@ -482,7 +482,7 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context)
* to be applied directly to a Query node. * to be applied directly to a Query node.
*/ */
Node * Node *
flatten_join_alias_vars(Query *root, Node *node) flatten_join_alias_vars(PlannerInfo *root, Node *node)
{ {
flatten_join_alias_vars_context context; flatten_join_alias_vars_context context;
...@@ -507,7 +507,7 @@ flatten_join_alias_vars_mutator(Node *node, ...@@ -507,7 +507,7 @@ flatten_join_alias_vars_mutator(Node *node,
/* No change unless Var belongs to a JOIN of the target level */ /* No change unless Var belongs to a JOIN of the target level */
if (var->varlevelsup != context->sublevels_up) if (var->varlevelsup != context->sublevels_up)
return node; /* no need to copy, really */ return node; /* no need to copy, really */
rte = rt_fetch(var->varno, context->root->rtable); rte = rt_fetch(var->varno, context->root->parse->rtable);
if (rte->rtekind != RTE_JOIN) if (rte->rtekind != RTE_JOIN)
return node; return node;
if (var->varattno == InvalidAttrNumber) if (var->varattno == InvalidAttrNumber)
...@@ -608,7 +608,7 @@ flatten_join_alias_vars_mutator(Node *node, ...@@ -608,7 +608,7 @@ flatten_join_alias_vars_mutator(Node *node,
* underlying base relids * underlying base relids
*/ */
static Relids static Relids
alias_relid_set(Query *root, Relids relids) alias_relid_set(PlannerInfo *root, Relids relids)
{ {
Relids result = NULL; Relids result = NULL;
Relids tmprelids; Relids tmprelids;
...@@ -617,7 +617,7 @@ alias_relid_set(Query *root, Relids relids) ...@@ -617,7 +617,7 @@ alias_relid_set(Query *root, Relids relids)
tmprelids = bms_copy(relids); tmprelids = bms_copy(relids);
while ((rtindex = bms_first_member(tmprelids)) >= 0) while ((rtindex = bms_first_member(tmprelids)) >= 0)
{ {
RangeTblEntry *rte = rt_fetch(rtindex, root->rtable); RangeTblEntry *rte = rt_fetch(rtindex, root->parse->rtable);
if (rte->rtekind == RTE_JOIN) if (rte->rtekind == RTE_JOIN)
result = bms_join(result, get_relids_for_join(root, rtindex)); result = bms_join(result, get_relids_for_join(root, rtindex));
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.68 2005/03/29 00:17:04 tgl Exp $ * $PostgreSQL: pgsql/src/backend/parser/parse_agg.c,v 1.69 2005/06/05 22:32:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -101,6 +101,7 @@ parseCheckAggregates(ParseState *pstate, Query *qry) ...@@ -101,6 +101,7 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
bool have_non_var_grouping; bool have_non_var_grouping;
ListCell *l; ListCell *l;
bool hasJoinRTEs; bool hasJoinRTEs;
PlannerInfo *root;
Node *clause; Node *clause;
/* This should only be called if we found aggregates or grouping */ /* This should only be called if we found aggregates or grouping */
...@@ -162,9 +163,22 @@ parseCheckAggregates(ParseState *pstate, Query *qry) ...@@ -162,9 +163,22 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
} }
} }
/*
* We use the planner's flatten_join_alias_vars routine to do the
* flattening; it wants a PlannerInfo root node, which fortunately
* can be mostly dummy.
*/
if (hasJoinRTEs) if (hasJoinRTEs)
groupClauses = (List *) flatten_join_alias_vars(qry, {
root = makeNode(PlannerInfo);
root->parse = qry;
root->hasJoinRTEs = true;
groupClauses = (List *) flatten_join_alias_vars(root,
(Node *) groupClauses); (Node *) groupClauses);
}
else
root = NULL; /* keep compiler quiet */
/* /*
* Detect whether any of the grouping expressions aren't simple Vars; * Detect whether any of the grouping expressions aren't simple Vars;
...@@ -186,13 +200,13 @@ parseCheckAggregates(ParseState *pstate, Query *qry) ...@@ -186,13 +200,13 @@ parseCheckAggregates(ParseState *pstate, Query *qry)
*/ */
clause = (Node *) qry->targetList; clause = (Node *) qry->targetList;
if (hasJoinRTEs) if (hasJoinRTEs)
clause = flatten_join_alias_vars(qry, clause); clause = flatten_join_alias_vars(root, clause);
check_ungrouped_columns(clause, pstate, check_ungrouped_columns(clause, pstate,
groupClauses, have_non_var_grouping); groupClauses, have_non_var_grouping);
clause = (Node *) qry->havingQual; clause = (Node *) qry->havingQual;
if (hasJoinRTEs) if (hasJoinRTEs)
clause = flatten_join_alias_vars(qry, clause); clause = flatten_join_alias_vars(root, clause);
check_ungrouped_columns(clause, pstate, check_ungrouped_columns(clause, pstate,
groupClauses, have_non_var_grouping); groupClauses, have_non_var_grouping);
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.179 2005/06/01 17:05:11 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.180 2005/06/05 22:32:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
* *
* The call convention for a restriction estimator (oprrest function) is * The call convention for a restriction estimator (oprrest function) is
* *
* Selectivity oprrest (Query *root, * Selectivity oprrest (PlannerInfo *root,
* Oid operator, * Oid operator,
* List *args, * List *args,
* int varRelid); * int varRelid);
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
* except that varRelid is not needed, and instead the join type is * except that varRelid is not needed, and instead the join type is
* supplied: * supplied:
* *
* Selectivity oprjoin (Query *root, * Selectivity oprjoin (PlannerInfo *root,
* Oid operator, * Oid operator,
* List *args, * List *args,
* JoinType jointype); * JoinType jointype);
...@@ -152,18 +152,18 @@ static double convert_one_bytea_to_scalar(unsigned char *value, int valuelen, ...@@ -152,18 +152,18 @@ static double convert_one_bytea_to_scalar(unsigned char *value, int valuelen,
int rangelo, int rangehi); int rangelo, int rangehi);
static unsigned char *convert_string_datum(Datum value, Oid typid); static unsigned char *convert_string_datum(Datum value, Oid typid);
static double convert_timevalue_to_scalar(Datum value, Oid typid); static double convert_timevalue_to_scalar(Datum value, Oid typid);
static bool get_restriction_variable(Query *root, List *args, int varRelid, static bool get_restriction_variable(PlannerInfo *root, List *args, int varRelid,
VariableStatData *vardata, Node **other, VariableStatData *vardata, Node **other,
bool *varonleft); bool *varonleft);
static void get_join_variables(Query *root, List *args, static void get_join_variables(PlannerInfo *root, List *args,
VariableStatData *vardata1, VariableStatData *vardata1,
VariableStatData *vardata2); VariableStatData *vardata2);
static void examine_variable(Query *root, Node *node, int varRelid, static void examine_variable(PlannerInfo *root, Node *node, int varRelid,
VariableStatData *vardata); VariableStatData *vardata);
static double get_variable_numdistinct(VariableStatData *vardata); static double get_variable_numdistinct(VariableStatData *vardata);
static bool get_variable_maximum(Query *root, VariableStatData *vardata, static bool get_variable_maximum(PlannerInfo *root, VariableStatData *vardata,
Oid sortop, Datum *max); Oid sortop, Datum *max);
static Selectivity prefix_selectivity(Query *root, Node *variable, static Selectivity prefix_selectivity(PlannerInfo *root, Node *variable,
Oid opclass, Const *prefix); Oid opclass, Const *prefix);
static Selectivity pattern_selectivity(Const *patt, Pattern_Type ptype); static Selectivity pattern_selectivity(Const *patt, Pattern_Type ptype);
static Datum string_to_datum(const char *str, Oid datatype); static Datum string_to_datum(const char *str, Oid datatype);
...@@ -182,7 +182,7 @@ static Const *string_to_bytea_const(const char *str, size_t str_len); ...@@ -182,7 +182,7 @@ static Const *string_to_bytea_const(const char *str, size_t str_len);
Datum Datum
eqsel(PG_FUNCTION_ARGS) eqsel(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Oid operator = PG_GETARG_OID(1); Oid operator = PG_GETARG_OID(1);
List *args = (List *) PG_GETARG_POINTER(2); List *args = (List *) PG_GETARG_POINTER(2);
int varRelid = PG_GETARG_INT32(3); int varRelid = PG_GETARG_INT32(3);
...@@ -377,7 +377,7 @@ eqsel(PG_FUNCTION_ARGS) ...@@ -377,7 +377,7 @@ eqsel(PG_FUNCTION_ARGS)
Datum Datum
neqsel(PG_FUNCTION_ARGS) neqsel(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Oid operator = PG_GETARG_OID(1); Oid operator = PG_GETARG_OID(1);
List *args = (List *) PG_GETARG_POINTER(2); List *args = (List *) PG_GETARG_POINTER(2);
int varRelid = PG_GETARG_INT32(3); int varRelid = PG_GETARG_INT32(3);
...@@ -420,7 +420,7 @@ neqsel(PG_FUNCTION_ARGS) ...@@ -420,7 +420,7 @@ neqsel(PG_FUNCTION_ARGS)
* it will return a default estimate. * it will return a default estimate.
*/ */
static double static double
scalarineqsel(Query *root, Oid operator, bool isgt, scalarineqsel(PlannerInfo *root, Oid operator, bool isgt,
VariableStatData *vardata, Datum constval, Oid consttype) VariableStatData *vardata, Datum constval, Oid consttype)
{ {
Form_pg_statistic stats; Form_pg_statistic stats;
...@@ -652,7 +652,7 @@ scalarineqsel(Query *root, Oid operator, bool isgt, ...@@ -652,7 +652,7 @@ scalarineqsel(Query *root, Oid operator, bool isgt,
Datum Datum
scalarltsel(PG_FUNCTION_ARGS) scalarltsel(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Oid operator = PG_GETARG_OID(1); Oid operator = PG_GETARG_OID(1);
List *args = (List *) PG_GETARG_POINTER(2); List *args = (List *) PG_GETARG_POINTER(2);
int varRelid = PG_GETARG_INT32(3); int varRelid = PG_GETARG_INT32(3);
...@@ -728,7 +728,7 @@ scalarltsel(PG_FUNCTION_ARGS) ...@@ -728,7 +728,7 @@ scalarltsel(PG_FUNCTION_ARGS)
Datum Datum
scalargtsel(PG_FUNCTION_ARGS) scalargtsel(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Oid operator = PG_GETARG_OID(1); Oid operator = PG_GETARG_OID(1);
List *args = (List *) PG_GETARG_POINTER(2); List *args = (List *) PG_GETARG_POINTER(2);
int varRelid = PG_GETARG_INT32(3); int varRelid = PG_GETARG_INT32(3);
...@@ -804,7 +804,7 @@ scalargtsel(PG_FUNCTION_ARGS) ...@@ -804,7 +804,7 @@ scalargtsel(PG_FUNCTION_ARGS)
static double static double
patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype) patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
#ifdef NOT_USED #ifdef NOT_USED
Oid operator = PG_GETARG_OID(1); Oid operator = PG_GETARG_OID(1);
...@@ -1073,7 +1073,7 @@ icnlikesel(PG_FUNCTION_ARGS) ...@@ -1073,7 +1073,7 @@ icnlikesel(PG_FUNCTION_ARGS)
* booltestsel - Selectivity of BooleanTest Node. * booltestsel - Selectivity of BooleanTest Node.
*/ */
Selectivity Selectivity
booltestsel(Query *root, BoolTestType booltesttype, Node *arg, booltestsel(PlannerInfo *root, BoolTestType booltesttype, Node *arg,
int varRelid, JoinType jointype) int varRelid, JoinType jointype)
{ {
VariableStatData vardata; VariableStatData vardata;
...@@ -1238,7 +1238,8 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg, ...@@ -1238,7 +1238,8 @@ booltestsel(Query *root, BoolTestType booltesttype, Node *arg,
* nulltestsel - Selectivity of NullTest Node. * nulltestsel - Selectivity of NullTest Node.
*/ */
Selectivity Selectivity
nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid) nulltestsel(PlannerInfo *root, NullTestType nulltesttype,
Node *arg, int varRelid)
{ {
VariableStatData vardata; VariableStatData vardata;
double selec; double selec;
...@@ -1310,7 +1311,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid) ...@@ -1310,7 +1311,7 @@ nulltestsel(Query *root, NullTestType nulltesttype, Node *arg, int varRelid)
Datum Datum
eqjoinsel(PG_FUNCTION_ARGS) eqjoinsel(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Oid operator = PG_GETARG_OID(1); Oid operator = PG_GETARG_OID(1);
List *args = (List *) PG_GETARG_POINTER(2); List *args = (List *) PG_GETARG_POINTER(2);
JoinType jointype = (JoinType) PG_GETARG_INT16(3); JoinType jointype = (JoinType) PG_GETARG_INT16(3);
...@@ -1570,7 +1571,7 @@ eqjoinsel(PG_FUNCTION_ARGS) ...@@ -1570,7 +1571,7 @@ eqjoinsel(PG_FUNCTION_ARGS)
Datum Datum
neqjoinsel(PG_FUNCTION_ARGS) neqjoinsel(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Oid operator = PG_GETARG_OID(1); Oid operator = PG_GETARG_OID(1);
List *args = (List *) PG_GETARG_POINTER(2); List *args = (List *) PG_GETARG_POINTER(2);
JoinType jointype = (JoinType) PG_GETARG_INT16(3); JoinType jointype = (JoinType) PG_GETARG_INT16(3);
...@@ -1720,7 +1721,7 @@ icnlikejoinsel(PG_FUNCTION_ARGS) ...@@ -1720,7 +1721,7 @@ icnlikejoinsel(PG_FUNCTION_ARGS)
* variable. * variable.
*/ */
void void
mergejoinscansel(Query *root, Node *clause, mergejoinscansel(PlannerInfo *root, Node *clause,
Selectivity *leftscan, Selectivity *leftscan,
Selectivity *rightscan) Selectivity *rightscan)
{ {
...@@ -1841,7 +1842,7 @@ typedef struct ...@@ -1841,7 +1842,7 @@ typedef struct
} GroupVarInfo; } GroupVarInfo;
static List * static List *
add_unique_group_var(Query *root, List *varinfos, add_unique_group_var(PlannerInfo *root, List *varinfos,
Node *var, VariableStatData *vardata) Node *var, VariableStatData *vardata)
{ {
GroupVarInfo *varinfo; GroupVarInfo *varinfo;
...@@ -1953,7 +1954,7 @@ add_unique_group_var(Query *root, List *varinfos, ...@@ -1953,7 +1954,7 @@ add_unique_group_var(Query *root, List *varinfos,
* do better). * do better).
*/ */
double double
estimate_num_groups(Query *root, List *groupExprs, double input_rows) estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows)
{ {
List *varinfos = NIL; List *varinfos = NIL;
double numdistinct; double numdistinct;
...@@ -2151,7 +2152,7 @@ estimate_num_groups(Query *root, List *groupExprs, double input_rows) ...@@ -2151,7 +2152,7 @@ estimate_num_groups(Query *root, List *groupExprs, double input_rows)
* inner rel is well-dispersed (or the alternatives seem much worse). * inner rel is well-dispersed (or the alternatives seem much worse).
*/ */
Selectivity Selectivity
estimate_hash_bucketsize(Query *root, Node *hashkey, double nbuckets) estimate_hash_bucketsize(PlannerInfo *root, Node *hashkey, double nbuckets)
{ {
VariableStatData vardata; VariableStatData vardata;
double estfract, double estfract,
...@@ -2840,7 +2841,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -2840,7 +2841,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
* and also indicate which side it was on and the other argument. * and also indicate which side it was on and the other argument.
* *
* Inputs: * Inputs:
* root: the Query * root: the planner info
* args: clause argument list * args: clause argument list
* varRelid: see specs for restriction selectivity functions * varRelid: see specs for restriction selectivity functions
* *
...@@ -2855,7 +2856,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid) ...@@ -2855,7 +2856,7 @@ convert_timevalue_to_scalar(Datum value, Oid typid)
* callers are expecting that the other side will act like a pseudoconstant. * callers are expecting that the other side will act like a pseudoconstant.
*/ */
static bool static bool
get_restriction_variable(Query *root, List *args, int varRelid, get_restriction_variable(PlannerInfo *root, List *args, int varRelid,
VariableStatData *vardata, Node **other, VariableStatData *vardata, Node **other,
bool *varonleft) bool *varonleft)
{ {
...@@ -2909,7 +2910,7 @@ get_restriction_variable(Query *root, List *args, int varRelid, ...@@ -2909,7 +2910,7 @@ get_restriction_variable(Query *root, List *args, int varRelid,
* Apply examine_variable() to each side of a join clause. * Apply examine_variable() to each side of a join clause.
*/ */
static void static void
get_join_variables(Query *root, List *args, get_join_variables(PlannerInfo *root, List *args,
VariableStatData *vardata1, VariableStatData *vardata2) VariableStatData *vardata1, VariableStatData *vardata2)
{ {
Node *left, Node *left,
...@@ -2931,7 +2932,7 @@ get_join_variables(Query *root, List *args, ...@@ -2931,7 +2932,7 @@ get_join_variables(Query *root, List *args,
* Fill in a VariableStatData struct to describe the expression. * Fill in a VariableStatData struct to describe the expression.
* *
* Inputs: * Inputs:
* root: the Query * root: the planner info
* node: the expression tree to examine * node: the expression tree to examine
* varRelid: see specs for restriction selectivity functions * varRelid: see specs for restriction selectivity functions
* *
...@@ -2952,7 +2953,7 @@ get_join_variables(Query *root, List *args, ...@@ -2952,7 +2953,7 @@ get_join_variables(Query *root, List *args,
* Caller is responsible for doing ReleaseVariableStats() before exiting. * Caller is responsible for doing ReleaseVariableStats() before exiting.
*/ */
static void static void
examine_variable(Query *root, Node *node, int varRelid, examine_variable(PlannerInfo *root, Node *node, int varRelid,
VariableStatData *vardata) VariableStatData *vardata)
{ {
Node *basenode; Node *basenode;
...@@ -2985,7 +2986,7 @@ examine_variable(Query *root, Node *node, int varRelid, ...@@ -2985,7 +2986,7 @@ examine_variable(Query *root, Node *node, int varRelid,
vardata->atttype = var->vartype; vardata->atttype = var->vartype;
vardata->atttypmod = var->vartypmod; vardata->atttypmod = var->vartypmod;
relid = getrelid(var->varno, root->rtable); relid = getrelid(var->varno, root->parse->rtable);
if (OidIsValid(relid)) if (OidIsValid(relid))
{ {
...@@ -3250,7 +3251,7 @@ get_variable_numdistinct(VariableStatData *vardata) ...@@ -3250,7 +3251,7 @@ get_variable_numdistinct(VariableStatData *vardata)
* minimum instead of the maximum, just pass the ">" operator instead.) * minimum instead of the maximum, just pass the ">" operator instead.)
*/ */
static bool static bool
get_variable_maximum(Query *root, VariableStatData *vardata, get_variable_maximum(PlannerInfo *root, VariableStatData *vardata,
Oid sortop, Datum *max) Oid sortop, Datum *max)
{ {
Datum tmax = 0; Datum tmax = 0;
...@@ -3696,7 +3697,7 @@ pattern_fixed_prefix(Const *patt, Pattern_Type ptype, ...@@ -3696,7 +3697,7 @@ pattern_fixed_prefix(Const *patt, Pattern_Type ptype,
* more useful to use the upper-bound code than not. * more useful to use the upper-bound code than not.
*/ */
static Selectivity static Selectivity
prefix_selectivity(Query *root, Node *variable, prefix_selectivity(PlannerInfo *root, Node *variable,
Oid opclass, Const *prefixcon) Oid opclass, Const *prefixcon)
{ {
Selectivity prefixsel; Selectivity prefixsel;
...@@ -4198,7 +4199,7 @@ string_to_bytea_const(const char *str, size_t str_len) ...@@ -4198,7 +4199,7 @@ string_to_bytea_const(const char *str, size_t str_len)
*/ */
static void static void
genericcostestimate(Query *root, genericcostestimate(PlannerInfo *root,
IndexOptInfo *index, List *indexQuals, IndexOptInfo *index, List *indexQuals,
Cost *indexStartupCost, Cost *indexStartupCost,
Cost *indexTotalCost, Cost *indexTotalCost,
...@@ -4327,7 +4328,7 @@ genericcostestimate(Query *root, ...@@ -4327,7 +4328,7 @@ genericcostestimate(Query *root,
Datum Datum
btcostestimate(PG_FUNCTION_ARGS) btcostestimate(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
IndexOptInfo *index = (IndexOptInfo *) PG_GETARG_POINTER(1); IndexOptInfo *index = (IndexOptInfo *) PG_GETARG_POINTER(1);
List *indexQuals = (List *) PG_GETARG_POINTER(2); List *indexQuals = (List *) PG_GETARG_POINTER(2);
Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3); Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3);
...@@ -4354,7 +4355,7 @@ btcostestimate(PG_FUNCTION_ARGS) ...@@ -4354,7 +4355,7 @@ btcostestimate(PG_FUNCTION_ARGS)
if (index->indexkeys[0] != 0) if (index->indexkeys[0] != 0)
{ {
/* Simple variable --- look to stats for the underlying table */ /* Simple variable --- look to stats for the underlying table */
relid = getrelid(index->rel->relid, root->rtable); relid = getrelid(index->rel->relid, root->parse->rtable);
Assert(relid != InvalidOid); Assert(relid != InvalidOid);
colnum = index->indexkeys[0]; colnum = index->indexkeys[0];
} }
...@@ -4406,7 +4407,7 @@ btcostestimate(PG_FUNCTION_ARGS) ...@@ -4406,7 +4407,7 @@ btcostestimate(PG_FUNCTION_ARGS)
Datum Datum
rtcostestimate(PG_FUNCTION_ARGS) rtcostestimate(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
IndexOptInfo *index = (IndexOptInfo *) PG_GETARG_POINTER(1); IndexOptInfo *index = (IndexOptInfo *) PG_GETARG_POINTER(1);
List *indexQuals = (List *) PG_GETARG_POINTER(2); List *indexQuals = (List *) PG_GETARG_POINTER(2);
Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3); Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3);
...@@ -4424,7 +4425,7 @@ rtcostestimate(PG_FUNCTION_ARGS) ...@@ -4424,7 +4425,7 @@ rtcostestimate(PG_FUNCTION_ARGS)
Datum Datum
hashcostestimate(PG_FUNCTION_ARGS) hashcostestimate(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
IndexOptInfo *index = (IndexOptInfo *) PG_GETARG_POINTER(1); IndexOptInfo *index = (IndexOptInfo *) PG_GETARG_POINTER(1);
List *indexQuals = (List *) PG_GETARG_POINTER(2); List *indexQuals = (List *) PG_GETARG_POINTER(2);
Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3); Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3);
...@@ -4442,7 +4443,7 @@ hashcostestimate(PG_FUNCTION_ARGS) ...@@ -4442,7 +4443,7 @@ hashcostestimate(PG_FUNCTION_ARGS)
Datum Datum
gistcostestimate(PG_FUNCTION_ARGS) gistcostestimate(PG_FUNCTION_ARGS)
{ {
Query *root = (Query *) PG_GETARG_POINTER(0); PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
IndexOptInfo *index = (IndexOptInfo *) PG_GETARG_POINTER(1); IndexOptInfo *index = (IndexOptInfo *) PG_GETARG_POINTER(1);
List *indexQuals = (List *) PG_GETARG_POINTER(2); List *indexQuals = (List *) PG_GETARG_POINTER(2);
Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3); Cost *indexStartupCost = (Cost *) PG_GETARG_POINTER(3);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.168 2005/04/21 19:18:13 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.169 2005/06/05 22:32:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -165,7 +165,8 @@ typedef enum NodeTag ...@@ -165,7 +165,8 @@ typedef enum NodeTag
/* /*
* TAGS FOR PLANNER NODES (relation.h) * TAGS FOR PLANNER NODES (relation.h)
*/ */
T_RelOptInfo = 500, T_PlannerInfo = 500,
T_RelOptInfo,
T_IndexOptInfo, T_IndexOptInfo,
T_Path, T_Path,
T_IndexPath, T_IndexPath,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.280 2005/06/05 00:38:10 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.281 2005/06/05 22:32:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -62,8 +62,9 @@ typedef uint32 AclMode; /* a bitmask of privilege bits */ ...@@ -62,8 +62,9 @@ typedef uint32 AclMode; /* a bitmask of privilege bits */
* Query - * Query -
* all statements are turned into a Query tree (via transformStmt) * all statements are turned into a Query tree (via transformStmt)
* for further processing by the optimizer * for further processing by the optimizer
* utility statements (i.e. non-optimizable statements) *
* have the *utilityStmt field set. * utility statements (i.e. non-optimizable statements) have the
* utilityStmt field set, and the Query itself is mostly dummy.
*/ */
typedef struct Query typedef struct Query
{ {
...@@ -121,17 +122,6 @@ typedef struct Query ...@@ -121,17 +122,6 @@ typedef struct Query
* ought to go in some sort of TopPlan plan node, not in the Query. * ought to go in some sort of TopPlan plan node, not in the Query.
*/ */
List *resultRelations; /* integer list of RT indexes, or NIL */ List *resultRelations; /* integer list of RT indexes, or NIL */
/* internal to planner */
List *base_rel_list; /* list of base-relation RelOptInfos */
List *other_rel_list; /* list of other 1-relation RelOptInfos */
List *join_rel_list; /* list of join-relation RelOptInfos */
List *equi_key_list; /* list of lists of equijoined
* PathKeyItems */
List *in_info_list; /* list of InClauseInfos */
List *query_pathkeys; /* desired pathkeys for query_planner() */
bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
bool hasHavingQual; /* true if havingQual was non-null */
} Query; } Query;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.109 2005/04/25 01:30:14 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.110 2005/06/05 22:32:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -46,6 +46,40 @@ typedef struct QualCost ...@@ -46,6 +46,40 @@ typedef struct QualCost
Cost per_tuple; /* per-evaluation cost */ Cost per_tuple; /* per-evaluation cost */
} QualCost; } QualCost;
/*----------
* PlannerInfo
* Per-query information for planning/optimization
*
* This struct is conventionally called "root" in all the planner routines.
* It holds links to all of the planner's working state, in addition to the
* original Query. Note that at present the planner extensively manipulates
* the passed-in Query data structure; someday that should stop.
*----------
*/
typedef struct PlannerInfo
{
NodeTag type;
Query *parse; /* the Query being planned */
List *base_rel_list; /* list of base-relation RelOptInfos */
List *other_rel_list; /* list of other 1-relation RelOptInfos */
List *join_rel_list; /* list of join-relation RelOptInfos */
List *equi_key_list; /* list of lists of equijoined
* PathKeyItems */
List *in_info_list; /* list of InClauseInfos */
List *query_pathkeys; /* desired pathkeys for query_planner(),
* and actual pathkeys afterwards */
bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
bool hasHavingQual; /* true if havingQual was non-null */
} PlannerInfo;
/*---------- /*----------
* RelOptInfo * RelOptInfo
* Per-relation information for planning/optimization * Per-relation information for planning/optimization
...@@ -55,7 +89,7 @@ typedef struct QualCost ...@@ -55,7 +89,7 @@ typedef struct QualCost
* In either case it is uniquely identified by an RT index. A "joinrel" * In either case it is uniquely identified by an RT index. A "joinrel"
* is the joining of two or more base rels. A joinrel is identified by * is the joining of two or more base rels. A joinrel is identified by
* the set of RT indexes for its component baserels. We create RelOptInfo * the set of RT indexes for its component baserels. We create RelOptInfo
* nodes for each baserel and joinrel, and store them in the Query's * nodes for each baserel and joinrel, and store them in the PlannerInfo's
* base_rel_list and join_rel_list respectively. * base_rel_list and join_rel_list respectively.
* *
* Note that there is only one joinrel for any given set of component * Note that there is only one joinrel for any given set of component
...@@ -778,7 +812,7 @@ typedef struct InnerIndexscanInfo ...@@ -778,7 +812,7 @@ typedef struct InnerIndexscanInfo
* When we convert top-level IN quals into join operations, we must restrict * When we convert top-level IN quals into join operations, we must restrict
* the order of joining and use special join methods at some join points. * the order of joining and use special join methods at some join points.
* We record information about each such IN clause in an InClauseInfo struct. * We record information about each such IN clause in an InClauseInfo struct.
* These structs are kept in the Query node's in_info_list. * These structs are kept in the PlannerInfo node's in_info_list.
*/ */
typedef struct InClauseInfo typedef struct InClauseInfo
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.67 2005/04/22 21:58:32 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.68 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -51,53 +51,53 @@ extern bool enable_mergejoin; ...@@ -51,53 +51,53 @@ extern bool enable_mergejoin;
extern bool enable_hashjoin; extern bool enable_hashjoin;
extern double clamp_row_est(double nrows); extern double clamp_row_est(double nrows);
extern void cost_seqscan(Path *path, Query *root, RelOptInfo *baserel); extern void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel);
extern void cost_index(IndexPath *path, Query *root, IndexOptInfo *index, extern void cost_index(IndexPath *path, PlannerInfo *root, IndexOptInfo *index,
List *indexQuals, bool is_injoin); List *indexQuals, bool is_injoin);
extern void cost_bitmap_heap_scan(Path *path, Query *root, RelOptInfo *baserel, extern void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel,
Path *bitmapqual, bool is_injoin); Path *bitmapqual, bool is_injoin);
extern void cost_bitmap_and_node(BitmapAndPath *path, Query *root); extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root);
extern void cost_bitmap_or_node(BitmapOrPath *path, Query *root); extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root);
extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec); extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec);
extern void cost_tidscan(Path *path, Query *root, extern void cost_tidscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, List *tideval); RelOptInfo *baserel, List *tideval);
extern void cost_subqueryscan(Path *path, RelOptInfo *baserel); extern void cost_subqueryscan(Path *path, RelOptInfo *baserel);
extern void cost_functionscan(Path *path, Query *root, extern void cost_functionscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel); RelOptInfo *baserel);
extern void cost_sort(Path *path, Query *root, extern void cost_sort(Path *path, PlannerInfo *root,
List *pathkeys, Cost input_cost, double tuples, int width); List *pathkeys, Cost input_cost, double tuples, int width);
extern void cost_material(Path *path, extern void cost_material(Path *path,
Cost input_cost, double tuples, int width); Cost input_cost, double tuples, int width);
extern void cost_agg(Path *path, Query *root, extern void cost_agg(Path *path, PlannerInfo *root,
AggStrategy aggstrategy, int numAggs, AggStrategy aggstrategy, int numAggs,
int numGroupCols, double numGroups, int numGroupCols, double numGroups,
Cost input_startup_cost, Cost input_total_cost, Cost input_startup_cost, Cost input_total_cost,
double input_tuples); double input_tuples);
extern void cost_group(Path *path, Query *root, extern void cost_group(Path *path, PlannerInfo *root,
int numGroupCols, double numGroups, int numGroupCols, double numGroups,
Cost input_startup_cost, Cost input_total_cost, Cost input_startup_cost, Cost input_total_cost,
double input_tuples); double input_tuples);
extern void cost_nestloop(NestPath *path, Query *root); extern void cost_nestloop(NestPath *path, PlannerInfo *root);
extern void cost_mergejoin(MergePath *path, Query *root); extern void cost_mergejoin(MergePath *path, PlannerInfo *root);
extern void cost_hashjoin(HashPath *path, Query *root); extern void cost_hashjoin(HashPath *path, PlannerInfo *root);
extern void cost_qual_eval(QualCost *cost, List *quals); extern void cost_qual_eval(QualCost *cost, List *quals);
extern void set_baserel_size_estimates(Query *root, RelOptInfo *rel); extern void set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel);
extern void set_joinrel_size_estimates(Query *root, RelOptInfo *rel, extern void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
RelOptInfo *outer_rel, RelOptInfo *outer_rel,
RelOptInfo *inner_rel, RelOptInfo *inner_rel,
JoinType jointype, JoinType jointype,
List *restrictlist); List *restrictlist);
extern void set_function_size_estimates(Query *root, RelOptInfo *rel); extern void set_function_size_estimates(PlannerInfo *root, RelOptInfo *rel);
/* /*
* prototypes for clausesel.c * prototypes for clausesel.c
* routines to compute clause selectivities * routines to compute clause selectivities
*/ */
extern Selectivity clauselist_selectivity(Query *root, extern Selectivity clauselist_selectivity(PlannerInfo *root,
List *clauses, List *clauses,
int varRelid, int varRelid,
JoinType jointype); JoinType jointype);
extern Selectivity clause_selectivity(Query *root, extern Selectivity clause_selectivity(PlannerInfo *root,
Node *clause, Node *clause,
int varRelid, int varRelid,
JoinType jointype); JoinType jointype);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/geqo.h,v 1.38 2004/12/31 22:03:36 pgsql Exp $ * $PostgreSQL: pgsql/src/include/optimizer/geqo.h,v 1.39 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -72,13 +72,14 @@ extern double Geqo_selection_bias; ...@@ -72,13 +72,14 @@ extern double Geqo_selection_bias;
*/ */
typedef struct typedef struct
{ {
Query *root; /* the query we are planning */ PlannerInfo *root; /* the query we are planning */
List *initial_rels; /* the base relations */ List *initial_rels; /* the base relations */
} GeqoEvalData; } GeqoEvalData;
/* routines in geqo_main.c */ /* routines in geqo_main.c */
extern RelOptInfo *geqo(Query *root, int number_of_rels, List *initial_rels); extern RelOptInfo *geqo(PlannerInfo *root,
int number_of_rels, List *initial_rels);
/* routines in geqo_eval.c */ /* routines in geqo_eval.c */
extern Cost geqo_eval(Gene *tour, int num_gene, GeqoEvalData *evaldata); extern Cost geqo_eval(Gene *tour, int num_gene, GeqoEvalData *evaldata);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/joininfo.h,v 1.28 2004/12/31 22:03:36 pgsql Exp $ * $PostgreSQL: pgsql/src/include/optimizer/joininfo.h,v 1.29 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
extern JoinInfo *find_joininfo_node(RelOptInfo *this_rel, Relids join_relids); extern JoinInfo *find_joininfo_node(RelOptInfo *this_rel, Relids join_relids);
extern JoinInfo *make_joininfo_node(RelOptInfo *this_rel, Relids join_relids); extern JoinInfo *make_joininfo_node(RelOptInfo *this_rel, Relids join_relids);
extern void add_join_clause_to_rels(Query *root, extern void add_join_clause_to_rels(PlannerInfo *root,
RestrictInfo *restrictinfo, RestrictInfo *restrictinfo,
Relids join_relids); Relids join_relids);
extern void remove_join_clause_from_rels(Query *root, extern void remove_join_clause_from_rels(PlannerInfo *root,
RestrictInfo *restrictinfo, RestrictInfo *restrictinfo,
Relids join_relids); Relids join_relids);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/pathnode.h,v 1.60 2005/04/22 21:58:32 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/pathnode.h,v 1.61 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -27,35 +27,35 @@ extern int compare_fractional_path_costs(Path *path1, Path *path2, ...@@ -27,35 +27,35 @@ extern int compare_fractional_path_costs(Path *path1, Path *path2,
extern void set_cheapest(RelOptInfo *parent_rel); extern void set_cheapest(RelOptInfo *parent_rel);
extern void add_path(RelOptInfo *parent_rel, Path *new_path); extern void add_path(RelOptInfo *parent_rel, Path *new_path);
extern Path *create_seqscan_path(Query *root, RelOptInfo *rel); extern Path *create_seqscan_path(PlannerInfo *root, RelOptInfo *rel);
extern IndexPath *create_index_path(Query *root, extern IndexPath *create_index_path(PlannerInfo *root,
IndexOptInfo *index, IndexOptInfo *index,
List *clause_groups, List *clause_groups,
List *pathkeys, List *pathkeys,
ScanDirection indexscandir, ScanDirection indexscandir,
bool isjoininner); bool isjoininner);
extern BitmapHeapPath *create_bitmap_heap_path(Query *root, extern BitmapHeapPath *create_bitmap_heap_path(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
Path *bitmapqual, Path *bitmapqual,
bool isjoininner); bool isjoininner);
extern BitmapAndPath *create_bitmap_and_path(Query *root, extern BitmapAndPath *create_bitmap_and_path(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
List *bitmapquals); List *bitmapquals);
extern BitmapOrPath *create_bitmap_or_path(Query *root, extern BitmapOrPath *create_bitmap_or_path(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
List *bitmapquals); List *bitmapquals);
extern TidPath *create_tidscan_path(Query *root, RelOptInfo *rel, extern TidPath *create_tidscan_path(PlannerInfo *root, RelOptInfo *rel,
List *tideval); List *tideval);
extern AppendPath *create_append_path(RelOptInfo *rel, List *subpaths); extern AppendPath *create_append_path(RelOptInfo *rel, List *subpaths);
extern ResultPath *create_result_path(RelOptInfo *rel, Path *subpath, extern ResultPath *create_result_path(RelOptInfo *rel, Path *subpath,
List *constantqual); List *constantqual);
extern MaterialPath *create_material_path(RelOptInfo *rel, Path *subpath); extern MaterialPath *create_material_path(RelOptInfo *rel, Path *subpath);
extern UniquePath *create_unique_path(Query *root, RelOptInfo *rel, extern UniquePath *create_unique_path(PlannerInfo *root, RelOptInfo *rel,
Path *subpath); Path *subpath);
extern Path *create_subqueryscan_path(RelOptInfo *rel, List *pathkeys); extern Path *create_subqueryscan_path(RelOptInfo *rel, List *pathkeys);
extern Path *create_functionscan_path(Query *root, RelOptInfo *rel); extern Path *create_functionscan_path(PlannerInfo *root, RelOptInfo *rel);
extern NestPath *create_nestloop_path(Query *root, extern NestPath *create_nestloop_path(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
JoinType jointype, JoinType jointype,
Path *outer_path, Path *outer_path,
...@@ -63,7 +63,7 @@ extern NestPath *create_nestloop_path(Query *root, ...@@ -63,7 +63,7 @@ extern NestPath *create_nestloop_path(Query *root,
List *restrict_clauses, List *restrict_clauses,
List *pathkeys); List *pathkeys);
extern MergePath *create_mergejoin_path(Query *root, extern MergePath *create_mergejoin_path(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
JoinType jointype, JoinType jointype,
Path *outer_path, Path *outer_path,
...@@ -74,7 +74,7 @@ extern MergePath *create_mergejoin_path(Query *root, ...@@ -74,7 +74,7 @@ extern MergePath *create_mergejoin_path(Query *root,
List *outersortkeys, List *outersortkeys,
List *innersortkeys); List *innersortkeys);
extern HashPath *create_hashjoin_path(Query *root, extern HashPath *create_hashjoin_path(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
JoinType jointype, JoinType jointype,
Path *outer_path, Path *outer_path,
...@@ -85,11 +85,11 @@ extern HashPath *create_hashjoin_path(Query *root, ...@@ -85,11 +85,11 @@ extern HashPath *create_hashjoin_path(Query *root,
/* /*
* prototypes for relnode.c * prototypes for relnode.c
*/ */
extern void build_base_rel(Query *root, int relid); extern void build_base_rel(PlannerInfo *root, int relid);
extern RelOptInfo *build_other_rel(Query *root, int relid); extern RelOptInfo *build_other_rel(PlannerInfo *root, int relid);
extern RelOptInfo *find_base_rel(Query *root, int relid); extern RelOptInfo *find_base_rel(PlannerInfo *root, int relid);
extern RelOptInfo *find_join_rel(Query *root, Relids relids); extern RelOptInfo *find_join_rel(PlannerInfo *root, Relids relids);
extern RelOptInfo *build_join_rel(Query *root, extern RelOptInfo *build_join_rel(PlannerInfo *root,
Relids joinrelids, Relids joinrelids,
RelOptInfo *outer_rel, RelOptInfo *outer_rel,
RelOptInfo *inner_rel, RelOptInfo *inner_rel,
......
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* paths.h * paths.h
* prototypes for various files in optimizer/path (were separate * prototypes for various files in optimizer/path
* header files)
* *
* *
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.83 2005/04/25 01:30:14 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.84 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -24,23 +23,23 @@ ...@@ -24,23 +23,23 @@
extern bool enable_geqo; extern bool enable_geqo;
extern int geqo_threshold; extern int geqo_threshold;
extern RelOptInfo *make_one_rel(Query *root); extern RelOptInfo *make_one_rel(PlannerInfo *root);
extern RelOptInfo *make_fromexpr_rel(Query *root, FromExpr *from); extern RelOptInfo *make_fromexpr_rel(PlannerInfo *root, FromExpr *from);
#ifdef OPTIMIZER_DEBUG #ifdef OPTIMIZER_DEBUG
extern void debug_print_rel(Query *root, RelOptInfo *rel); extern void debug_print_rel(PlannerInfo *root, RelOptInfo *rel);
#endif #endif
/* /*
* indxpath.c * indxpath.c
* routines to generate index paths * routines to generate index paths
*/ */
extern void create_index_paths(Query *root, RelOptInfo *rel); extern void create_index_paths(PlannerInfo *root, RelOptInfo *rel);
extern List *generate_bitmap_or_paths(Query *root, RelOptInfo *rel, extern List *generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
List *clauses, List *outer_clauses, List *clauses, List *outer_clauses,
bool isjoininner, bool isjoininner,
Relids outer_relids); Relids outer_relids);
extern Path *best_inner_indexscan(Query *root, RelOptInfo *rel, extern Path *best_inner_indexscan(PlannerInfo *root, RelOptInfo *rel,
Relids outer_relids, JoinType jointype); Relids outer_relids, JoinType jointype);
extern List *group_clauses_by_indexkey(IndexOptInfo *index, extern List *group_clauses_by_indexkey(IndexOptInfo *index,
List *clauses, List *outer_clauses, List *clauses, List *outer_clauses,
...@@ -49,7 +48,7 @@ extern bool match_index_to_operand(Node *operand, int indexcol, ...@@ -49,7 +48,7 @@ extern bool match_index_to_operand(Node *operand, int indexcol,
IndexOptInfo *index); IndexOptInfo *index);
extern List *expand_indexqual_conditions(IndexOptInfo *index, extern List *expand_indexqual_conditions(IndexOptInfo *index,
List *clausegroups); List *clausegroups);
extern void check_partial_indexes(Query *root, RelOptInfo *rel); extern void check_partial_indexes(PlannerInfo *root, RelOptInfo *rel);
extern bool pred_test(List *predicate_list, List *restrictinfo_list); extern bool pred_test(List *predicate_list, List *restrictinfo_list);
extern List *flatten_clausegroups_list(List *clausegroups); extern List *flatten_clausegroups_list(List *clausegroups);
...@@ -57,19 +56,19 @@ extern List *flatten_clausegroups_list(List *clausegroups); ...@@ -57,19 +56,19 @@ extern List *flatten_clausegroups_list(List *clausegroups);
* orindxpath.c * orindxpath.c
* additional routines for indexable OR clauses * additional routines for indexable OR clauses
*/ */
extern bool create_or_index_quals(Query *root, RelOptInfo *rel); extern bool create_or_index_quals(PlannerInfo *root, RelOptInfo *rel);
/* /*
* tidpath.h * tidpath.h
* routines to generate tid paths * routines to generate tid paths
*/ */
extern void create_tidscan_paths(Query *root, RelOptInfo *rel); extern void create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel);
/* /*
* joinpath.c * joinpath.c
* routines to create join paths * routines to create join paths
*/ */
extern void add_paths_to_joinrel(Query *root, RelOptInfo *joinrel, extern void add_paths_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *outerrel,
RelOptInfo *innerrel, RelOptInfo *innerrel,
JoinType jointype, JoinType jointype,
...@@ -79,9 +78,9 @@ extern void add_paths_to_joinrel(Query *root, RelOptInfo *joinrel, ...@@ -79,9 +78,9 @@ extern void add_paths_to_joinrel(Query *root, RelOptInfo *joinrel,
* joinrels.c * joinrels.c
* routines to determine which relations to join * routines to determine which relations to join
*/ */
extern List *make_rels_by_joins(Query *root, int level, List **joinrels); extern List *make_rels_by_joins(PlannerInfo *root, int level, List **joinrels);
extern RelOptInfo *make_jointree_rel(Query *root, Node *jtnode); extern RelOptInfo *make_jointree_rel(PlannerInfo *root, Node *jtnode);
extern RelOptInfo *make_join_rel(Query *root, extern RelOptInfo *make_join_rel(PlannerInfo *root,
RelOptInfo *rel1, RelOptInfo *rel2, RelOptInfo *rel1, RelOptInfo *rel2,
JoinType jointype); JoinType jointype);
...@@ -97,10 +96,10 @@ typedef enum ...@@ -97,10 +96,10 @@ typedef enum
PATHKEYS_DIFFERENT /* neither pathkey includes the other */ PATHKEYS_DIFFERENT /* neither pathkey includes the other */
} PathKeysComparison; } PathKeysComparison;
extern void add_equijoined_keys(Query *root, RestrictInfo *restrictinfo); extern void add_equijoined_keys(PlannerInfo *root, RestrictInfo *restrictinfo);
extern bool exprs_known_equal(Query *root, Node *item1, Node *item2); extern bool exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2);
extern void generate_implied_equalities(Query *root); extern void generate_implied_equalities(PlannerInfo *root);
extern List *canonicalize_pathkeys(Query *root, List *pathkeys); extern List *canonicalize_pathkeys(PlannerInfo *root, List *pathkeys);
extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2); extern PathKeysComparison compare_pathkeys(List *keys1, List *keys2);
extern bool pathkeys_contained_in(List *keys1, List *keys2); extern bool pathkeys_contained_in(List *keys1, List *keys2);
extern PathKeysComparison compare_noncanonical_pathkeys(List *keys1, extern PathKeysComparison compare_noncanonical_pathkeys(List *keys1,
...@@ -111,29 +110,29 @@ extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, ...@@ -111,29 +110,29 @@ extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys,
extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths, extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths,
List *pathkeys, List *pathkeys,
double fraction); double fraction);
extern List *build_index_pathkeys(Query *root, IndexOptInfo *index, extern List *build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index,
ScanDirection scandir); ScanDirection scandir);
extern List *build_subquery_pathkeys(Query *root, RelOptInfo *rel, extern List *convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
Query *subquery); List *subquery_pathkeys);
extern List *build_join_pathkeys(Query *root, extern List *build_join_pathkeys(PlannerInfo *root,
RelOptInfo *joinrel, RelOptInfo *joinrel,
JoinType jointype, JoinType jointype,
List *outer_pathkeys); List *outer_pathkeys);
extern List *make_pathkeys_for_sortclauses(List *sortclauses, extern List *make_pathkeys_for_sortclauses(List *sortclauses,
List *tlist); List *tlist);
extern void cache_mergeclause_pathkeys(Query *root, extern void cache_mergeclause_pathkeys(PlannerInfo *root,
RestrictInfo *restrictinfo); RestrictInfo *restrictinfo);
extern List *find_mergeclauses_for_pathkeys(Query *root, extern List *find_mergeclauses_for_pathkeys(PlannerInfo *root,
List *pathkeys, List *pathkeys,
List *restrictinfos); List *restrictinfos);
extern List *make_pathkeys_for_mergeclauses(Query *root, extern List *make_pathkeys_for_mergeclauses(PlannerInfo *root,
List *mergeclauses, List *mergeclauses,
RelOptInfo *rel); RelOptInfo *rel);
extern int pathkeys_useful_for_merging(Query *root, extern int pathkeys_useful_for_merging(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
List *pathkeys); List *pathkeys);
extern int pathkeys_useful_for_ordering(Query *root, List *pathkeys); extern int pathkeys_useful_for_ordering(PlannerInfo *root, List *pathkeys);
extern List *truncate_useless_pathkeys(Query *root, extern List *truncate_useless_pathkeys(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
List *pathkeys); List *pathkeys);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/plancat.h,v 1.35 2004/12/31 22:03:36 pgsql Exp $ * $PostgreSQL: pgsql/src/include/optimizer/plancat.h,v 1.36 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
extern void get_relation_info(Oid relationObjectId, RelOptInfo *rel); extern void get_relation_info(Oid relationObjectId, RelOptInfo *rel);
extern List *build_physical_tlist(Query *root, RelOptInfo *rel); extern List *build_physical_tlist(PlannerInfo *root, RelOptInfo *rel);
extern List *find_inheritance_children(Oid inhparent); extern List *find_inheritance_children(Oid inhparent);
...@@ -27,12 +27,12 @@ extern bool has_subclass(Oid relationId); ...@@ -27,12 +27,12 @@ extern bool has_subclass(Oid relationId);
extern bool has_unique_index(RelOptInfo *rel, AttrNumber attno); extern bool has_unique_index(RelOptInfo *rel, AttrNumber attno);
extern Selectivity restriction_selectivity(Query *root, extern Selectivity restriction_selectivity(PlannerInfo *root,
Oid operator, Oid operator,
List *args, List *args,
int varRelid); int varRelid);
extern Selectivity join_selectivity(Query *root, extern Selectivity join_selectivity(PlannerInfo *root,
Oid operator, Oid operator,
List *args, List *args,
JoinType jointype); JoinType jointype);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.85 2005/05/22 22:30:20 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.86 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -20,33 +20,34 @@ ...@@ -20,33 +20,34 @@
/* /*
* prototypes for plan/planmain.c * prototypes for plan/planmain.c
*/ */
extern void query_planner(Query *root, List *tlist, double tuple_fraction, extern void query_planner(PlannerInfo *root, List *tlist,
Path **cheapest_path, Path **sorted_path); double tuple_fraction,
Path **cheapest_path, Path **sorted_path);
/* /*
* prototypes for plan/planagg.c * prototypes for plan/planagg.c
*/ */
extern Plan *optimize_minmax_aggregates(Query *root, List *tlist, extern Plan *optimize_minmax_aggregates(PlannerInfo *root, List *tlist,
Path *best_path); Path *best_path);
/* /*
* prototypes for plan/createplan.c * prototypes for plan/createplan.c
*/ */
extern Plan *create_plan(Query *root, Path *best_path); extern Plan *create_plan(PlannerInfo *root, Path *best_path);
extern SubqueryScan *make_subqueryscan(List *qptlist, List *qpqual, extern SubqueryScan *make_subqueryscan(List *qptlist, List *qpqual,
Index scanrelid, Plan *subplan); Index scanrelid, Plan *subplan);
extern Append *make_append(List *appendplans, bool isTarget, List *tlist); extern Append *make_append(List *appendplans, bool isTarget, List *tlist);
extern Sort *make_sort_from_sortclauses(Query *root, List *sortcls, extern Sort *make_sort_from_sortclauses(PlannerInfo *root, List *sortcls,
Plan *lefttree); Plan *lefttree);
extern Sort *make_sort_from_groupcols(Query *root, List *groupcls, extern Sort *make_sort_from_groupcols(PlannerInfo *root, List *groupcls,
AttrNumber *grpColIdx, Plan *lefttree); AttrNumber *grpColIdx, Plan *lefttree);
extern List *order_qual_clauses(Query *root, List *clauses); extern List *order_qual_clauses(PlannerInfo *root, List *clauses);
extern Agg *make_agg(Query *root, List *tlist, List *qual, extern Agg *make_agg(PlannerInfo *root, List *tlist, List *qual,
AggStrategy aggstrategy, AggStrategy aggstrategy,
int numGroupCols, AttrNumber *grpColIdx, int numGroupCols, AttrNumber *grpColIdx,
long numGroups, int numAggs, long numGroups, int numAggs,
Plan *lefttree); Plan *lefttree);
extern Group *make_group(Query *root, List *tlist, List *qual, extern Group *make_group(PlannerInfo *root, List *tlist, List *qual,
int numGroupCols, AttrNumber *grpColIdx, int numGroupCols, AttrNumber *grpColIdx,
double numGroups, double numGroups,
Plan *lefttree); Plan *lefttree);
...@@ -62,10 +63,10 @@ extern bool is_projection_capable_plan(Plan *plan); ...@@ -62,10 +63,10 @@ extern bool is_projection_capable_plan(Plan *plan);
/* /*
* prototypes for plan/initsplan.c * prototypes for plan/initsplan.c
*/ */
extern void add_base_rels_to_query(Query *root, Node *jtnode); extern void add_base_rels_to_query(PlannerInfo *root, Node *jtnode);
extern void build_base_rel_tlists(Query *root, List *final_tlist); extern void build_base_rel_tlists(PlannerInfo *root, List *final_tlist);
extern Relids distribute_quals_to_rels(Query *root, Node *jtnode); extern Relids distribute_quals_to_rels(PlannerInfo *root, Node *jtnode);
extern void process_implied_equality(Query *root, extern void process_implied_equality(PlannerInfo *root,
Node *item1, Node *item2, Node *item1, Node *item2,
Oid sortop1, Oid sortop2, Oid sortop1, Oid sortop2,
Relids item1_relids, Relids item2_relids, Relids item1_relids, Relids item2_relids,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/planner.h,v 1.32 2004/12/31 22:03:36 pgsql Exp $ * $PostgreSQL: pgsql/src/include/optimizer/planner.h,v 1.33 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -23,6 +23,7 @@ extern ParamListInfo PlannerBoundParamList; /* current boundParams */ ...@@ -23,6 +23,7 @@ extern ParamListInfo PlannerBoundParamList; /* current boundParams */
extern Plan *planner(Query *parse, bool isCursor, int cursorOptions, extern Plan *planner(Query *parse, bool isCursor, int cursorOptions,
ParamListInfo boundParams); ParamListInfo boundParams);
extern Plan *subquery_planner(Query *parse, double tuple_fraction); extern Plan *subquery_planner(Query *parse, double tuple_fraction,
List **subquery_pathkeys);
#endif /* PLANNER_H */ #endif /* PLANNER_H */
...@@ -7,14 +7,13 @@ ...@@ -7,14 +7,13 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/prep.h,v 1.49 2005/03/28 00:58:26 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/prep.h,v 1.50 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef PREP_H #ifndef PREP_H
#define PREP_H #define PREP_H
#include "nodes/parsenodes.h"
#include "nodes/plannodes.h" #include "nodes/plannodes.h"
#include "nodes/relation.h" #include "nodes/relation.h"
...@@ -25,13 +24,13 @@ ...@@ -25,13 +24,13 @@
extern int from_collapse_limit; extern int from_collapse_limit;
extern int join_collapse_limit; extern int join_collapse_limit;
extern Node *pull_up_IN_clauses(Query *parse, Node *node); extern Node *pull_up_IN_clauses(PlannerInfo *root, Node *node);
extern Node *pull_up_subqueries(Query *parse, Node *jtnode, extern Node *pull_up_subqueries(PlannerInfo *root, Node *jtnode,
bool below_outer_join); bool below_outer_join);
extern void reduce_outer_joins(Query *parse); extern void reduce_outer_joins(PlannerInfo *root);
extern Node *simplify_jointree(Query *parse, Node *jtnode); extern Node *simplify_jointree(PlannerInfo *root, Node *jtnode);
extern Relids get_relids_in_jointree(Node *jtnode); extern Relids get_relids_in_jointree(Node *jtnode);
extern Relids get_relids_for_join(Query *parse, int joinrelid); extern Relids get_relids_for_join(PlannerInfo *root, int joinrelid);
/* /*
* prototypes for prepqual.c * prototypes for prepqual.c
...@@ -41,16 +40,16 @@ extern Expr *canonicalize_qual(Expr *qual); ...@@ -41,16 +40,16 @@ extern Expr *canonicalize_qual(Expr *qual);
/* /*
* prototypes for preptlist.c * prototypes for preptlist.c
*/ */
extern List *preprocess_targetlist(Query *parse, List *tlist); extern List *preprocess_targetlist(PlannerInfo *root, List *tlist);
/* /*
* prototypes for prepunion.c * prototypes for prepunion.c
*/ */
extern Plan *plan_set_operations(Query *parse, List **sortClauses); extern Plan *plan_set_operations(PlannerInfo *root, List **sortClauses);
extern List *find_all_inheritors(Oid parentrel); extern List *find_all_inheritors(Oid parentrel);
extern List *expand_inherited_rtentry(Query *parse, Index rti); extern List *expand_inherited_rtentry(PlannerInfo *root, Index rti);
extern Node *adjust_inherited_attrs(Node *node, extern Node *adjust_inherited_attrs(Node *node,
Index old_rt_index, Oid old_relid, Index old_rt_index, Oid old_relid,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.29 2005/04/25 02:14:48 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/restrictinfo.h,v 1.30 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "nodes/relation.h" #include "nodes/relation.h"
extern RestrictInfo *make_restrictinfo(Expr *clause, bool is_pushed_down, extern RestrictInfo *make_restrictinfo(Expr *clause, bool is_pushed_down,
bool valid_everywhere); bool valid_everywhere);
extern List *make_restrictinfo_from_bitmapqual(Path *bitmapqual, extern List *make_restrictinfo_from_bitmapqual(Path *bitmapqual,
...@@ -25,10 +26,10 @@ extern bool restriction_is_or_clause(RestrictInfo *restrictinfo); ...@@ -25,10 +26,10 @@ extern bool restriction_is_or_clause(RestrictInfo *restrictinfo);
extern List *get_actual_clauses(List *restrictinfo_list); extern List *get_actual_clauses(List *restrictinfo_list);
extern void get_actual_join_clauses(List *restrictinfo_list, extern void get_actual_join_clauses(List *restrictinfo_list,
List **joinquals, List **otherquals); List **joinquals, List **otherquals);
extern List *remove_redundant_join_clauses(Query *root, extern List *remove_redundant_join_clauses(PlannerInfo *root,
List *restrictinfo_list, List *restrictinfo_list,
bool isouterjoin); bool isouterjoin);
extern List *select_nonredundant_join_clauses(Query *root, extern List *select_nonredundant_join_clauses(PlannerInfo *root,
List *restrictinfo_list, List *restrictinfo_list,
List *reference_list, List *reference_list,
bool isouterjoin); bool isouterjoin);
......
...@@ -5,26 +5,27 @@ ...@@ -5,26 +5,27 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/subselect.h,v 1.24 2005/04/11 23:06:56 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/subselect.h,v 1.25 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef SUBSELECT_H #ifndef SUBSELECT_H
#define SUBSELECT_H #define SUBSELECT_H
#include "nodes/parsenodes.h"
#include "nodes/plannodes.h" #include "nodes/plannodes.h"
#include "nodes/relation.h"
extern Index PlannerQueryLevel; /* level of current query */ extern Index PlannerQueryLevel; /* level of current query */
extern List *PlannerInitPlan; /* init subplans for current query */ extern List *PlannerInitPlan; /* init subplans for current query */
extern List *PlannerParamList; /* to keep track of cross-level Params */ extern List *PlannerParamList; /* to keep track of cross-level Params */
extern int PlannerPlanId; /* to assign unique ID to subquery plans */ extern int PlannerPlanId; /* to assign unique ID to subquery plans */
extern Node *convert_IN_to_join(Query *parse, SubLink *sublink); extern Node *convert_IN_to_join(PlannerInfo *root, SubLink *sublink);
extern Node *SS_replace_correlation_vars(Node *expr); extern Node *SS_replace_correlation_vars(Node *expr);
extern Node *SS_process_sublinks(Node *expr, bool isQual); extern Node *SS_process_sublinks(Node *expr, bool isQual);
extern void SS_finalize_plan(Plan *plan, List *rtable); extern void SS_finalize_plan(Plan *plan, List *rtable);
extern Param *SS_make_initplan_from_plan(Query *root, Plan *plan, extern Param *SS_make_initplan_from_plan(PlannerInfo *root, Plan *plan,
Oid resulttype, int32 resulttypmod); Oid resulttype, int32 resulttypmod);
#endif /* SUBSELECT_H */ #endif /* SUBSELECT_H */
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* var.h * var.h
* prototypes for var.c. * prototypes for optimizer/util/var.c.
* *
* *
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/var.h,v 1.32 2004/12/31 22:03:36 pgsql Exp $ * $PostgreSQL: pgsql/src/include/optimizer/var.h,v 1.33 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -25,6 +25,6 @@ extern bool contain_vars_of_level(Node *node, int levelsup); ...@@ -25,6 +25,6 @@ extern bool contain_vars_of_level(Node *node, int levelsup);
extern bool contain_vars_above_level(Node *node, int levelsup); extern bool contain_vars_above_level(Node *node, int levelsup);
extern int find_minimum_var_level(Node *node); extern int find_minimum_var_level(Node *node);
extern List *pull_var_clause(Node *node, bool includeUpperVars); extern List *pull_var_clause(Node *node, bool includeUpperVars);
extern Node *flatten_join_alias_vars(Query *root, Node *node); extern Node *flatten_join_alias_vars(PlannerInfo *root, Node *node);
#endif /* VAR_H */ #endif /* VAR_H */
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.22 2005/03/06 22:15:05 tgl Exp $ * $PostgreSQL: pgsql/src/include/utils/selfuncs.h,v 1.23 2005/06/05 22:32:58 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define SELFUNCS_H #define SELFUNCS_H
#include "fmgr.h" #include "fmgr.h"
#include "nodes/parsenodes.h" #include "nodes/relation.h"
/* /*
...@@ -108,19 +108,19 @@ extern Datum icregexnejoinsel(PG_FUNCTION_ARGS); ...@@ -108,19 +108,19 @@ extern Datum icregexnejoinsel(PG_FUNCTION_ARGS);
extern Datum nlikejoinsel(PG_FUNCTION_ARGS); extern Datum nlikejoinsel(PG_FUNCTION_ARGS);
extern Datum icnlikejoinsel(PG_FUNCTION_ARGS); extern Datum icnlikejoinsel(PG_FUNCTION_ARGS);
extern Selectivity booltestsel(Query *root, BoolTestType booltesttype, extern Selectivity booltestsel(PlannerInfo *root, BoolTestType booltesttype,
Node *arg, int varRelid, JoinType jointype); Node *arg, int varRelid, JoinType jointype);
extern Selectivity nulltestsel(Query *root, NullTestType nulltesttype, extern Selectivity nulltestsel(PlannerInfo *root, NullTestType nulltesttype,
Node *arg, int varRelid); Node *arg, int varRelid);
extern void mergejoinscansel(Query *root, Node *clause, extern void mergejoinscansel(PlannerInfo *root, Node *clause,
Selectivity *leftscan, Selectivity *leftscan,
Selectivity *rightscan); Selectivity *rightscan);
extern double estimate_num_groups(Query *root, List *groupExprs, extern double estimate_num_groups(PlannerInfo *root, List *groupExprs,
double input_rows); double input_rows);
extern Selectivity estimate_hash_bucketsize(Query *root, Node *hashkey, extern Selectivity estimate_hash_bucketsize(PlannerInfo *root, Node *hashkey,
double nbuckets); double nbuckets);
extern Datum btcostestimate(PG_FUNCTION_ARGS); extern Datum btcostestimate(PG_FUNCTION_ARGS);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment