1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

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.
This commit is contained in:
Tom Lane
2005-06-05 22:32:58 +00:00
parent 22dbd54047
commit 9ab4d98168
51 changed files with 852 additions and 707 deletions

View File

@ -8,7 +8,7 @@
*
*
* 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 */
int geqo_threshold;
static void set_base_rel_pathlists(Query *root);
static void set_plain_rel_pathlist(Query *root, RelOptInfo *rel,
static void set_base_rel_pathlists(PlannerInfo *root);
static void set_plain_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
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,
List *inheritlist);
static void set_subquery_pathlist(Query *root, RelOptInfo *rel,
static void set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
Index rti, RangeTblEntry *rte);
static void set_function_pathlist(Query *root, RelOptInfo *rel,
static void set_function_pathlist(PlannerInfo *root, RelOptInfo *rel,
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);
static bool subquery_is_pushdown_safe(Query *subquery, Query *topquery,
bool *differentTypes);
@ -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.
*/
RelOptInfo *
make_one_rel(Query *root)
make_one_rel(PlannerInfo *root)
{
RelOptInfo *rel;
@ -82,9 +82,10 @@ make_one_rel(Query *root)
/*
* 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.
@ -101,7 +102,7 @@ make_one_rel(Query *root)
* Each useful path is attached to its relation's 'pathlist' field.
*/
static void
set_base_rel_pathlists(Query *root)
set_base_rel_pathlists(PlannerInfo *root)
{
ListCell *l;
@ -113,7 +114,7 @@ set_base_rel_pathlists(Query *root)
List *inheritlist;
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)
{
@ -147,7 +148,7 @@ set_base_rel_pathlists(Query *root)
* Build access paths for a plain relation (no subquery, no inheritance)
*/
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 */
set_baserel_size_estimates(root, rel);
@ -204,7 +205,7 @@ set_plain_rel_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
* not the same size.
*/
static void
set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
set_inherited_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
Index rti, RangeTblEntry *rte,
List *inheritlist)
{
@ -217,7 +218,7 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
* XXX for now, can't handle inherited expansion of FOR UPDATE/SHARE;
* can we do better?
*/
if (list_member_int(root->rowMarks, parentRTindex))
if (list_member_int(root->parse->rowMarks, parentRTindex))
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("SELECT FOR UPDATE/SHARE is not supported for inheritance queries")));
@ -241,7 +242,7 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
ListCell *parentvars;
ListCell *childvars;
childrte = rt_fetch(childRTindex, root->rtable);
childrte = rt_fetch(childRTindex, root->parse->rtable);
childOID = childrte->relid;
/*
@ -321,12 +322,13 @@ set_inherited_rel_pathlist(Query *root, RelOptInfo *rel,
* Build the (single) access path for a subquery RTE
*/
static void
set_subquery_pathlist(Query *root, RelOptInfo *rel,
set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
Index rti, RangeTblEntry *rte)
{
Query *subquery = rte->subquery;
bool *differentTypes;
List *pathkeys;
List *subquery_pathkeys;
/* We need a workspace for keeping track of set-op type coercions */
differentTypes = (bool *)
@ -379,7 +381,8 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel,
pfree(differentTypes);
/* 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 */
rel->tuples = rel->subplan->plan_rows;
@ -388,7 +391,7 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel,
set_baserel_size_estimates(root, rel);
/* Convert subquery pathkeys to outer representation */
pathkeys = build_subquery_pathkeys(root, rel, subquery);
pathkeys = convert_subquery_pathkeys(root, rel, subquery_pathkeys);
/* Generate appropriate path */
add_path(rel, create_subqueryscan_path(rel, pathkeys));
@ -402,7 +405,7 @@ set_subquery_pathlist(Query *root, RelOptInfo *rel,
* Build the (single) access path for a function RTE
*/
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 */
set_function_size_estimates(root, rel);
@ -419,7 +422,7 @@ set_function_pathlist(Query *root, RelOptInfo *rel, RangeTblEntry *rte)
* Build access paths for a FromExpr jointree node.
*/
RelOptInfo *
make_fromexpr_rel(Query *root, FromExpr *from)
make_fromexpr_rel(PlannerInfo *root, FromExpr *from)
{
int levels_needed;
List *initial_rels = NIL;
@ -483,7 +486,7 @@ make_fromexpr_rel(Query *root, FromExpr *from)
* the result of joining all the original relations together.
*/
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;
int lev;
@ -867,7 +870,7 @@ print_relids(Relids relids)
}
static void
print_restrictclauses(Query *root, List *clauses)
print_restrictclauses(PlannerInfo *root, List *clauses)
{
ListCell *l;
@ -875,14 +878,14 @@ print_restrictclauses(Query *root, List *clauses)
{
RestrictInfo *c = lfirst(l);
print_expr((Node *) c->clause, root->rtable);
print_expr((Node *) c->clause, root->parse->rtable);
if (lnext(l))
printf(", ");
}
}
static void
print_path(Query *root, Path *path, int indent)
print_path(PlannerInfo *root, Path *path, int indent)
{
const char *ptype;
bool join = false;
@ -958,7 +961,7 @@ print_path(Query *root, Path *path, int indent)
for (i = 0; i < indent; i++)
printf("\t");
printf(" pathkeys: ");
print_pathkeys(path->pathkeys, root->rtable);
print_pathkeys(path->pathkeys, root->parse->rtable);
}
if (join)
@ -994,7 +997,7 @@ print_path(Query *root, Path *path, int indent)
}
void
debug_print_rel(Query *root, RelOptInfo *rel)
debug_print_rel(PlannerInfo *root, RelOptInfo *rel)
{
ListCell *l;

View File

@ -8,7 +8,7 @@
*
*
* 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,
* scalarltsel/scalargtsel; perhaps some day we can generalize the approach.
*/
Selectivity
clauselist_selectivity(Query *root,
clauselist_selectivity(PlannerInfo *root,
List *clauses,
int varRelid,
JoinType jointype)
@ -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.
*/
Selectivity
clause_selectivity(Query *root,
clause_selectivity(PlannerInfo *root,
Node *clause,
int varRelid,
JoinType jointype)
@ -476,7 +476,7 @@ clause_selectivity(Query *root,
if (var->varlevelsup == 0 &&
(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)
{

View File

@ -49,7 +49,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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;
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);
static Selectivity join_in_selectivity(JoinPath *path, Query *root);
static void set_rel_width(Query *root, RelOptInfo *rel);
static Selectivity join_in_selectivity(JoinPath *path, PlannerInfo *root);
static void set_rel_width(PlannerInfo *root, RelOptInfo *rel);
static double relation_byte_size(double tuples, int width);
static double page_size(double tuples, int width);
@ -138,7 +138,7 @@ clamp_row_est(double nrows)
* Determines and returns the cost of scanning a relation sequentially.
*/
void
cost_seqscan(Path *path, Query *root,
cost_seqscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel)
{
Cost startup_cost = 0;
@ -227,7 +227,6 @@ cost_nonsequential_access(double relpages)
* NOTE: an indexscan plan node can actually represent several passes,
* but here we consider the cost of just one pass.
*
* 'root' is the query root
* 'index' is the index to be used
* '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
@ -246,7 +245,7 @@ cost_nonsequential_access(double relpages)
* it was a list of bare clause expressions.
*/
void
cost_index(IndexPath *path, Query *root,
cost_index(IndexPath *path, PlannerInfo *root,
IndexOptInfo *index,
List *indexQuals,
bool is_injoin)
@ -418,14 +417,13 @@ cost_index(IndexPath *path, Query *root,
* Determines and returns the cost of scanning a relation using a bitmap
* index-then-heap plan.
*
* 'root' is the query root
* 'baserel' is the relation to be scanned
* 'bitmapqual' is a tree of IndexPaths, BitmapAndPaths, and BitmapOrPaths
* '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)
*/
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)
{
Cost startup_cost = 0;
@ -534,7 +532,7 @@ cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
* to warrant treating it as one.
*/
void
cost_bitmap_and_node(BitmapAndPath *path, Query *root)
cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
{
Cost totalCost;
Selectivity selec;
@ -577,7 +575,7 @@ cost_bitmap_and_node(BitmapAndPath *path, Query *root)
* See comments for cost_bitmap_and_node.
*/
void
cost_bitmap_or_node(BitmapOrPath *path, Query *root)
cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
{
Cost totalCost;
Selectivity selec;
@ -620,7 +618,7 @@ cost_bitmap_or_node(BitmapOrPath *path, Query *root)
* Determines and returns the cost of scanning a relation using TIDs.
*/
void
cost_tidscan(Path *path, Query *root,
cost_tidscan(Path *path, PlannerInfo *root,
RelOptInfo *baserel, List *tideval)
{
Cost startup_cost = 0;
@ -684,7 +682,7 @@ cost_subqueryscan(Path *path, RelOptInfo *baserel)
* Determines and returns the cost of scanning a function RTE.
*/
void
cost_functionscan(Path *path, Query *root, RelOptInfo *baserel)
cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel)
{
Cost startup_cost = 0;
Cost run_cost = 0;
@ -748,7 +746,7 @@ cost_functionscan(Path *path, Query *root, RelOptInfo *baserel)
* of sort keys, which all callers *could* supply.)
*/
void
cost_sort(Path *path, Query *root,
cost_sort(Path *path, PlannerInfo *root,
List *pathkeys, Cost input_cost, double tuples, int width)
{
Cost startup_cost = input_cost;
@ -857,7 +855,7 @@ cost_material(Path *path,
* are for appropriately-sorted input.
*/
void
cost_agg(Path *path, Query *root,
cost_agg(Path *path, PlannerInfo *root,
AggStrategy aggstrategy, int numAggs,
int numGroupCols, double numGroups,
Cost input_startup_cost, Cost input_total_cost,
@ -925,7 +923,7 @@ cost_agg(Path *path, Query *root,
* input.
*/
void
cost_group(Path *path, Query *root,
cost_group(Path *path, PlannerInfo *root,
int numGroupCols, double numGroups,
Cost input_startup_cost, Cost input_total_cost,
double input_tuples)
@ -954,7 +952,7 @@ cost_group(Path *path, Query *root,
* 'path' is already filled in except for the cost fields
*/
void
cost_nestloop(NestPath *path, Query *root)
cost_nestloop(NestPath *path, PlannerInfo *root)
{
Path *outer_path = path->outerjoinpath;
Path *inner_path = path->innerjoinpath;
@ -1046,7 +1044,7 @@ cost_nestloop(NestPath *path, Query *root)
* sort is needed because the source path is already ordered.
*/
void
cost_mergejoin(MergePath *path, Query *root)
cost_mergejoin(MergePath *path, PlannerInfo *root)
{
Path *outer_path = path->jpath.outerjoinpath;
Path *inner_path = path->jpath.innerjoinpath;
@ -1275,7 +1273,7 @@ cost_mergejoin(MergePath *path, Query *root)
* Note: path's hashclauses should be a subset of the joinrestrictinfo list
*/
void
cost_hashjoin(HashPath *path, Query *root)
cost_hashjoin(HashPath *path, PlannerInfo *root)
{
Path *outer_path = path->jpath.outerjoinpath;
Path *inner_path = path->jpath.innerjoinpath;
@ -1673,7 +1671,7 @@ cost_qual_eval_walker(Node *node, QualCost *total)
* seems OK to live with the approximation.
*/
static Selectivity
approx_selectivity(Query *root, List *quals, JoinType jointype)
approx_selectivity(PlannerInfo *root, List *quals, JoinType jointype)
{
Selectivity total = 1.0;
ListCell *l;
@ -1703,7 +1701,7 @@ approx_selectivity(Query *root, List *quals, JoinType jointype)
* baserestrictcost: estimated cost of evaluating baserestrictinfo clauses.
*/
void
set_baserel_size_estimates(Query *root, RelOptInfo *rel)
set_baserel_size_estimates(PlannerInfo *root, RelOptInfo *rel)
{
double nrows;
@ -1749,7 +1747,7 @@ set_baserel_size_estimates(Query *root, RelOptInfo *rel)
* build_joinrel_tlist, and baserestrictcost is not used for join rels.
*/
void
set_joinrel_size_estimates(Query *root, RelOptInfo *rel,
set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
RelOptInfo *outer_rel,
RelOptInfo *inner_rel,
JoinType jointype,
@ -1836,7 +1834,7 @@ set_joinrel_size_estimates(Query *root, RelOptInfo *rel,
* 'path' is already filled in except for the cost fields
*/
static Selectivity
join_in_selectivity(JoinPath *path, Query *root)
join_in_selectivity(JoinPath *path, PlannerInfo *root)
{
RelOptInfo *innerrel;
UniquePath *innerunique;
@ -1896,7 +1894,7 @@ join_in_selectivity(JoinPath *path, Query *root)
* We set the same fields as set_baserel_size_estimates.
*/
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 */
Assert(rel->relid > 0);
@ -1929,7 +1927,7 @@ set_function_size_estimates(Query *root, RelOptInfo *rel)
* building join relations.
*/
static void
set_rel_width(Query *root, RelOptInfo *rel)
set_rel_width(PlannerInfo *root, RelOptInfo *rel)
{
int32 tuple_width = 0;
ListCell *tllist;
@ -1960,7 +1958,7 @@ set_rel_width(Query *root, RelOptInfo *rel)
continue;
}
relid = getrelid(var->varno, root->rtable);
relid = getrelid(var->varno, root->parse->rtable);
if (relid != InvalidOid)
{
item_width = get_attavgwidth(relid, var->varattno);

View File

@ -9,7 +9,7 @@
*
*
* 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 @@
((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,
bool istoplevel, bool isjoininner,
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 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,
int indexcol, Oid opclass,
RestrictInfo *rinfo,
@ -75,7 +75,7 @@ static bool list_matches_any_index(List *clauses, RelOptInfo *rel,
Relids outer_relids);
static bool matches_any_index(RestrictInfo *rinfo, RelOptInfo *rel,
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);
static bool match_boolean_index_clause(Node *clause, int indexcol,
IndexOptInfo *index);
@ -124,7 +124,7 @@ static Const *string_to_const(const char *str, Oid datatype);
* Note: check_partial_indexes() must have been run previously.
*/
void
create_index_paths(Query *root, RelOptInfo *rel)
create_index_paths(PlannerInfo *root, RelOptInfo *rel)
{
List *indexpaths;
List *bitindexpaths;
@ -231,7 +231,7 @@ create_index_paths(Query *root, RelOptInfo *rel)
*----------
*/
static List *
find_usable_indexes(Query *root, RelOptInfo *rel,
find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
List *clauses, List *outer_clauses,
bool istoplevel, bool isjoininner,
Relids outer_relids)
@ -363,7 +363,7 @@ find_usable_indexes(Query *root, RelOptInfo *rel,
* ORs. (See find_usable_indexes() for motivation.)
*/
List *
generate_bitmap_or_paths(Query *root, RelOptInfo *rel,
generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel,
List *clauses, List *outer_clauses,
bool isjoininner,
Relids outer_relids)
@ -473,7 +473,7 @@ generate_bitmap_or_paths(Query *root, RelOptInfo *rel,
* combining multiple inputs.
*/
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);
Path **patharray;
@ -593,7 +593,7 @@ bitmap_path_comparator(const void *a, const void *b)
* inputs.
*/
static Cost
bitmap_and_cost_est(Query *root, RelOptInfo *rel, List *paths)
bitmap_and_cost_est(PlannerInfo *root, RelOptInfo *rel, List *paths)
{
BitmapAndPath apath;
Path bpath;
@ -864,7 +864,7 @@ indexable_operator(Expr *clause, Oid opclass, bool indexkey_on_left)
* depending on whether the predicate is satisfied for this query.
*/
void
check_partial_indexes(Query *root, RelOptInfo *rel)
check_partial_indexes(PlannerInfo *root, RelOptInfo *rel)
{
List *restrictinfo_list = rel->baserestrictinfo;
ListCell *ilist;
@ -1675,7 +1675,7 @@ matches_any_index(RestrictInfo *rinfo, RelOptInfo *rel, Relids outer_relids)
* sufficient to return a single "best" path.
*/
Path *
best_inner_indexscan(Query *root, RelOptInfo *rel,
best_inner_indexscan(PlannerInfo *root, RelOptInfo *rel,
Relids outer_relids, JoinType jointype)
{
Path *cheapest;
@ -1828,7 +1828,7 @@ best_inner_indexscan(Query *root, RelOptInfo *rel,
* indicating that there isn't any potential win here.
*/
static List *
find_clauses_for_join(Query *root, RelOptInfo *rel,
find_clauses_for_join(PlannerInfo *root, RelOptInfo *rel,
Relids outer_relids, bool isouterjoin)
{
List *clause_list = NIL;

View File

@ -8,7 +8,7 @@
*
*
* 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 @@
#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,
List *restrictlist, List *mergeclause_list,
JoinType jointype);
static void match_unsorted_outer(Query *root, RelOptInfo *joinrel,
static void match_unsorted_outer(PlannerInfo *root, RelOptInfo *joinrel,
RelOptInfo *outerrel, RelOptInfo *innerrel,
List *restrictlist, List *mergeclause_list,
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,
List *restrictlist, JoinType jointype);
static List *select_mergejoin_clauses(RelOptInfo *joinrel,
@ -54,7 +54,7 @@ static List *select_mergejoin_clauses(RelOptInfo *joinrel,
* paths found so far.
*/
void
add_paths_to_joinrel(Query *root,
add_paths_to_joinrel(PlannerInfo *root,
RelOptInfo *joinrel,
RelOptInfo *outerrel,
RelOptInfo *innerrel,
@ -133,7 +133,7 @@ add_paths_to_joinrel(Query *root,
* 'jointype' is the type of join to do
*/
static void
sort_inner_and_outer(Query *root,
sort_inner_and_outer(PlannerInfo *root,
RelOptInfo *joinrel,
RelOptInfo *outerrel,
RelOptInfo *innerrel,
@ -324,7 +324,7 @@ sort_inner_and_outer(Query *root,
* 'jointype' is the type of join to do
*/
static void
match_unsorted_outer(Query *root,
match_unsorted_outer(PlannerInfo *root,
RelOptInfo *joinrel,
RelOptInfo *outerrel,
RelOptInfo *innerrel,
@ -664,7 +664,7 @@ match_unsorted_outer(Query *root,
* 'jointype' is the type of join to do
*/
static void
hash_inner_and_outer(Query *root,
hash_inner_and_outer(PlannerInfo *root,
RelOptInfo *joinrel,
RelOptInfo *outerrel,
RelOptInfo *innerrel,

View File

@ -8,7 +8,7 @@
*
*
* 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 @@
#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,
ListCell *other_rels);
static List *make_rels_by_clauseless_joins(Query *root,
static List *make_rels_by_clauseless_joins(PlannerInfo *root,
RelOptInfo *old_rel,
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);
* joinrels[j], 1 <= j < level, is a list of rels containing j items.
*/
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 *new_rels;
@ -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.)
*/
static List *
make_rels_by_clause_joins(Query *root,
make_rels_by_clause_joins(PlannerInfo *root,
RelOptInfo *old_rel,
ListCell *other_rels)
{
@ -335,7 +335,7 @@ make_rels_by_clause_joins(Query *root,
* work for joining to joinrels too.
*/
static List *
make_rels_by_clauseless_joins(Query *root,
make_rels_by_clauseless_joins(PlannerInfo *root,
RelOptInfo *old_rel,
ListCell *other_rels)
{
@ -373,7 +373,7 @@ make_rels_by_clauseless_joins(Query *root,
* out of an IN, so the routine name is a slight misnomer.
*/
static bool
is_inside_IN(Query *root, RelOptInfo *rel)
is_inside_IN(PlannerInfo *root, RelOptInfo *rel)
{
ListCell *l;
@ -395,7 +395,7 @@ is_inside_IN(Query *root, RelOptInfo *rel)
* path that corresponds exactly to what the user wrote.
*/
RelOptInfo *
make_jointree_rel(Query *root, Node *jtnode)
make_jointree_rel(PlannerInfo *root, Node *jtnode)
{
if (IsA(jtnode, RangeTblRef))
{
@ -460,7 +460,7 @@ make_jointree_rel(Query *root, Node *jtnode)
* happen when working with IN clauses that have been turned into joins.
*/
RelOptInfo *
make_join_rel(Query *root, RelOptInfo *rel1, RelOptInfo *rel2,
make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
JoinType jointype)
{
Relids joinrelids;

View File

@ -8,7 +8,7 @@
*
*
* 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 @@
*----------
*/
bool
create_or_index_quals(Query *root, RelOptInfo *rel)
create_or_index_quals(PlannerInfo *root, RelOptInfo *rel)
{
BitmapOrPath *bestpath = NULL;
RestrictInfo *bestrinfo = NULL;

View File

@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* 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 @@
static PathKeyItem *makePathKeyItem(Node *key, Oid sortop, bool checkType);
static List *make_canonical_pathkey(Query *root, PathKeyItem *item);
static Var *find_indexkey_var(Query *root, RelOptInfo *rel,
static List *make_canonical_pathkey(PlannerInfo *root, PathKeyItem *item);
static Var *find_indexkey_var(PlannerInfo *root, RelOptInfo *rel,
AttrNumber varattno);
@ -87,7 +87,7 @@ makePathKeyItem(Node *key, Oid sortop, bool checkType)
* that involves an equijoined variable.
*/
void
add_equijoined_keys(Query *root, RestrictInfo *restrictinfo)
add_equijoined_keys(PlannerInfo *root, RestrictInfo *restrictinfo)
{
Expr *clause = restrictinfo->clause;
PathKeyItem *item1 = makePathKeyItem(get_leftop(clause),
@ -198,7 +198,7 @@ add_equijoined_keys(Query *root, RestrictInfo *restrictinfo)
* restrictinfo datastructures for each pair.
*/
void
generate_implied_equalities(Query *root)
generate_implied_equalities(PlannerInfo *root)
{
ListCell *cursetlink;
@ -293,7 +293,7 @@ generate_implied_equalities(Query *root)
* check that case if it's possible to pass identical items.
*/
bool
exprs_known_equal(Query *root, Node *item1, Node *item2)
exprs_known_equal(PlannerInfo *root, Node *item1, Node *item2)
{
ListCell *cursetlink;
@ -333,7 +333,7 @@ exprs_known_equal(Query *root, Node *item1, Node *item2)
* scanning the WHERE clause for equijoin operators.
*/
static List *
make_canonical_pathkey(Query *root, PathKeyItem *item)
make_canonical_pathkey(PlannerInfo *root, PathKeyItem *item)
{
List *newset;
ListCell *cursetlink;
@ -358,7 +358,7 @@ make_canonical_pathkey(Query *root, PathKeyItem *item)
* scanning the WHERE clause for equijoin operators.
*/
List *
canonicalize_pathkeys(Query *root, List *pathkeys)
canonicalize_pathkeys(PlannerInfo *root, List *pathkeys)
{
List *new_pathkeys = NIL;
ListCell *l;
@ -398,10 +398,10 @@ canonicalize_pathkeys(Query *root, List *pathkeys)
* If not, return 0 (without actually adding it to our equi_key_list).
*
* This is a hack to support the rather bogus heuristics in
* build_subquery_pathkeys.
* convert_subquery_pathkeys.
*/
static int
count_canonical_peers(Query *root, PathKeyItem *item)
count_canonical_peers(PlannerInfo *root, PathKeyItem *item)
{
ListCell *cursetlink;
@ -441,7 +441,7 @@ compare_pathkeys(List *keys1, List *keys2)
/*
* 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
Assert(list_member_ptr(root->equi_key_list, subkey1));
@ -647,7 +647,7 @@ get_cheapest_fractional_path_for_pathkeys(List *paths,
* current query. Caller should do truncate_useless_pathkeys().
*/
List *
build_index_pathkeys(Query *root,
build_index_pathkeys(PlannerInfo *root,
IndexOptInfo *index,
ScanDirection scandir)
{
@ -714,7 +714,7 @@ build_index_pathkeys(Query *root,
* gin up a Var node the hard way.
*/
static Var *
find_indexkey_var(Query *root, RelOptInfo *rel, AttrNumber varattno)
find_indexkey_var(PlannerInfo *root, RelOptInfo *rel, AttrNumber varattno)
{
ListCell *temp;
Index relid;
@ -732,24 +732,28 @@ find_indexkey_var(Query *root, RelOptInfo *rel, AttrNumber varattno)
}
relid = rel->relid;
reloid = getrelid(relid, root->rtable);
reloid = getrelid(relid, root->parse->rtable);
get_atttypetypmod(reloid, varattno, &vartypeid, &type_mod);
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
* result (in the terms of the outer query). The subquery must already
* have been planned, so that its query_pathkeys field has been set.
* result, in the terms of the outer query. This is essentially a
* 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(),
* because we select keys in a way that takes usefulness of the keys into
* account.
*/
List *
build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
List *subquery_pathkeys)
{
List *retval = NIL;
int retvallen = 0;
@ -757,7 +761,7 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
List *sub_tlist = rel->subplan->targetlist;
ListCell *i;
foreach(i, subquery->query_pathkeys)
foreach(i, subquery_pathkeys)
{
List *sub_pathkey = (List *) lfirst(i);
ListCell *j;
@ -869,7 +873,7 @@ build_subquery_pathkeys(Query *root, RelOptInfo *rel, Query *subquery)
* Returns the list of new path keys.
*/
List *
build_join_pathkeys(Query *root,
build_join_pathkeys(PlannerInfo *root,
RelOptInfo *joinrel,
JoinType jointype,
List *outer_pathkeys)
@ -954,7 +958,7 @@ make_pathkeys_for_sortclauses(List *sortclauses,
* problem for normal planning, but it is an issue for GEQO planning.
*/
void
cache_mergeclause_pathkeys(Query *root, RestrictInfo *restrictinfo)
cache_mergeclause_pathkeys(PlannerInfo *root, RestrictInfo *restrictinfo)
{
Node *key;
PathKeyItem *item;
@ -1000,7 +1004,7 @@ cache_mergeclause_pathkeys(Query *root, RestrictInfo *restrictinfo)
* of the join.
*/
List *
find_mergeclauses_for_pathkeys(Query *root,
find_mergeclauses_for_pathkeys(PlannerInfo *root,
List *pathkeys,
List *restrictinfos)
{
@ -1093,7 +1097,7 @@ find_mergeclauses_for_pathkeys(Query *root,
* just make the keys, eh?
*/
List *
make_pathkeys_for_mergeclauses(Query *root,
make_pathkeys_for_mergeclauses(PlannerInfo *root,
List *mergeclauses,
RelOptInfo *rel)
{
@ -1162,7 +1166,7 @@ make_pathkeys_for_mergeclauses(Query *root,
* to be more trouble than it's worth.
*/
int
pathkeys_useful_for_merging(Query *root, RelOptInfo *rel, List *pathkeys)
pathkeys_useful_for_merging(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
{
int useful = 0;
ListCell *i;
@ -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).
*/
int
pathkeys_useful_for_ordering(Query *root, List *pathkeys)
pathkeys_useful_for_ordering(PlannerInfo *root, List *pathkeys)
{
if (root->query_pathkeys == NIL)
return 0; /* no special ordering requested */
@ -1248,7 +1252,7 @@ pathkeys_useful_for_ordering(Query *root, List *pathkeys)
* Shorten the given pathkey list to just the useful pathkeys.
*/
List *
truncate_useless_pathkeys(Query *root,
truncate_useless_pathkeys(PlannerInfo *root,
RelOptInfo *rel,
List *pathkeys)
{

View File

@ -9,7 +9,7 @@
*
*
* 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 @@
#include "parser/parse_coerce.h"
#include "utils/lsyscache.h"
static List *TidqualFromRestrictinfo(Relids relids, List *restrictinfo);
static bool isEvaluable(int varno, Node *node);
static Node *TidequalClause(int varno, OpExpr *node);
static List *TidqualFromExpr(int varno, Expr *expr);
static bool
isEvaluable(int varno, Node *node)
{
@ -228,7 +230,7 @@ TidqualFromRestrictinfo(Relids relids, List *restrictinfo)
* Candidate paths are added to the rel's pathlist (using add_path).
*/
void
create_tidscan_paths(Query *root, RelOptInfo *rel)
create_tidscan_paths(PlannerInfo *root, RelOptInfo *rel)
{
List *tideval = TidqualFromRestrictinfo(rel->relids,
rel->baserestrictinfo);