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);
......
This diff is collapsed.
...@@ -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
......
This diff is collapsed.
...@@ -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);
......
This diff is collapsed.
...@@ -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);
} }
......
This diff is collapsed.
...@@ -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,
double tuple_fraction,
Path **cheapest_path, Path **sorted_path); 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