diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/nodes/nodes.h | 18 | ||||
-rw-r--r-- | src/include/nodes/plannodes.h | 14 | ||||
-rw-r--r-- | src/include/nodes/relation.h | 106 | ||||
-rw-r--r-- | src/include/optimizer/cost.h | 46 | ||||
-rw-r--r-- | src/include/optimizer/pathnode.h | 31 | ||||
-rw-r--r-- | src/include/optimizer/paths.h | 8 | ||||
-rw-r--r-- | src/include/optimizer/plancat.h | 20 | ||||
-rw-r--r-- | src/include/optimizer/planmain.h | 5 |
8 files changed, 136 insertions, 112 deletions
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index 94641eff086..e66d6c4dfba 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: nodes.h,v 1.59 1999/12/16 17:24:19 momjian Exp $ + * $Id: nodes.h,v 1.60 2000/01/09 00:26:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -82,6 +82,7 @@ typedef enum NodeTag T_JoinInfo, T_Stream, T_TidPath, + T_IndexOptInfo, /*--------------------- * TAGS FOR EXECUTOR NODES (execnodes.h) @@ -286,12 +287,17 @@ extern void *copyObject(void *obj); extern bool equal(void *a, void *b); -/* ---------------- - * I don't know why this is here. Most likely a hack.. - * -cim 6/3/90 - * ---------------- +/* + * Typedefs for identifying qualifier selectivities and plan costs as such. + * These are just plain "double"s, but declaring a variable as Selectivity + * or Cost makes the intent more obvious. + * + * These could have gone into plannodes.h or some such, but many files + * depend on them... */ -typedef float Cost; +typedef double Selectivity; /* fraction of tuples a qualifier will pass */ +typedef double Cost; /* execution cost (in page-access units) */ + /* * CmdType - diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index 9cd06e2d932..324423aa956 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: plannodes.h,v 1.34 1999/11/23 20:07:02 momjian Exp $ + * $Id: plannodes.h,v 1.35 2000/01/09 00:26:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -63,10 +63,12 @@ typedef struct Plan { NodeTag type; + + /* planner's estimates of cost and result size */ Cost cost; - int plan_size; + double plan_rows; int plan_width; - int plan_tupperpage; + EState *state; /* at execution time, state's of * individual nodes point to one EState * for the whole top-level plan */ @@ -185,10 +187,10 @@ typedef struct IndexScan */ typedef struct TidScan { - Scan scan; + Scan scan; bool needRescan; - List *tideval; - TidScanState *tidstate; + List *tideval; + TidScanState *tidstate; } TidScan; /* diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 0f143017b2a..55850cef5e1 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: relation.h,v 1.39 1999/11/23 20:07:02 momjian Exp $ + * $Id: relation.h,v 1.40 2000/01/09 00:26:44 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -33,13 +33,10 @@ typedef List *Relids; * * relids - List of base-relation identifiers; it is a base relation * if there is just one, a join relation if more than one - * indexed - true if the relation has secondary indices - * pages - number of pages in the relation - * tuples - number of tuples in the relation - * size - estimated number of tuples in the relation after restriction - * clauses have been applied + * rows - estimated number of tuples in the relation after restriction + * clauses have been applied (ie, output rows of a plan for it) * width - avg. number of bytes per tuple in the relation after the - * appropriate projections have been done + * appropriate projections have been done (ie, output width) * targetlist - List of TargetList nodes * pathlist - List of Path nodes, one for each potentially useful * method of generating the relation @@ -47,20 +44,11 @@ typedef List *Relids; * pruneable - flag to let the planner know whether it can prune the * pathlist of this RelOptInfo or not. * - * * If the relation is a (secondary) index it will have the following - * fields set: - * - * classlist - List of PG_AMOPCLASS OIDs for the index - * indexkeys - List of base-relation attribute numbers that are index keys - * ordering - List of PG_OPERATOR OIDs which order the indexscan result - * relam - the OID of the pg_am of the index - * - * NB. the last element of the arrays classlist, indexkeys and ordering - * is always 0. + * * If the relation is a base relation it will have these fields set: * - * Index relations do not participate in the join tree in the way - * that regular base relations do, but it is still convenient to - * represent them by RelOptInfos. + * indexed - true if the relation has secondary indices + * pages - number of disk pages in relation + * tuples - number of tuples in relation (not considering restrictions) * * * The presence of the remaining fields depends on the restrictions * and joins that the relation participates in: @@ -79,16 +67,11 @@ typedef struct RelOptInfo NodeTag type; /* all relations included in this RelOptInfo */ - Relids relids; /* integer list of base relids */ - - /* catalog statistics information */ - bool indexed; - int pages; - int tuples; + Relids relids; /* integer list of base relids (RT indexes) */ - /* estimates generated by planner. XXX int is probably too small... */ - int size; - int width; + /* size estimates generated by planner */ + double rows; /* estimated number of result tuples */ + int width; /* estimated avg width of result tuples */ /* materialization information */ List *targetlist; @@ -96,14 +79,10 @@ typedef struct RelOptInfo struct Path *cheapestpath; bool pruneable; - /* used solely by indices: */ - Oid *classlist; /* classes of AM operators */ - int *indexkeys; /* keys over which we're indexing */ - Oid *ordering; /* OIDs of sort operators for each key */ - Oid relam; /* OID of the access method (in pg_am) */ - - Oid indproc; /* if a functional index */ - List *indpred; /* if a partial index */ + /* statistics from pg_class (only valid if it's a base rel!) */ + bool indexed; + long pages; + double tuples; /* used by various scans and joins: */ List *restrictinfo; /* RestrictInfo structures */ @@ -116,6 +95,48 @@ typedef struct RelOptInfo } RelOptInfo; /* + * IndexOptInfo + * Per-index information for planning/optimization + * + * Prior to Postgres 7.0, RelOptInfo was used to describe both relations + * and indexes, but that created confusion without actually doing anything + * useful. So now we have a separate IndexOptInfo struct for indexes. + * + * indexoid - OID of the index relation itself + * pages - number of disk pages in index + * tuples - number of index tuples in index + * classlist - List of PG_AMOPCLASS OIDs for the index + * indexkeys - List of base-relation attribute numbers that are index keys + * ordering - List of PG_OPERATOR OIDs which order the indexscan result + * relam - the OID of the pg_am of the index + * indproc - OID of the function if a functional index, else 0 + * indpred - index predicate if a partial index, else NULL + * + * NB. the last element of the arrays classlist, indexkeys and ordering + * is always 0. + */ + +typedef struct IndexOptInfo +{ + NodeTag type; + + Oid indexoid; /* OID of the index relation */ + + /* statistics from pg_class */ + long pages; + double tuples; + + /* index descriptor information */ + Oid *classlist; /* classes of AM operators */ + int *indexkeys; /* keys over which we're indexing */ + Oid *ordering; /* OIDs of sort operators for each key */ + Oid relam; /* OID of the access method (in pg_am) */ + + Oid indproc; /* if a functional index */ + List *indpred; /* if a partial index */ +} IndexOptInfo; + +/* * PathKeys * * The sort ordering of a path is represented by a list of sublists of @@ -208,8 +229,6 @@ typedef struct JoinPath { Path path; - List *pathinfo; /* copy of parent->restrictinfo; REMOVE? */ - Path *outerjoinpath; /* path for the outer side of the join */ Path *innerjoinpath; /* path for the inner side of the join */ } JoinPath; @@ -296,10 +315,10 @@ typedef struct RestrictInfo NodeTag type; Expr *clause; /* the represented clause of WHERE cond */ - Cost selectivity; /* estimated selectivity */ /* only used if clause is an OR clause: */ - List *subclauseindices; /* lists of indexes matching subclauses */ + List *subclauseindices; /* indexes matching subclauses */ + /* subclauseindices is a List of Lists of IndexOptInfos */ /* valid if clause is mergejoinable, else InvalidOid: */ Oid mergejoinoperator; /* copy of clause operator */ @@ -346,7 +365,8 @@ typedef struct JoinInfo * cinfo -- if NULL, this stream node referes to the path node. * Otherwise this is a pointer to the current clause. * clausetype -- whether cinfo is in loc_restrictinfo or pathinfo in the - * path node (XXX this is now used only by dead code...) + * path node (XXX this is now used only by dead code, which is + * good because the distinction no longer exists...) * upstream -- linked list pointer upwards * downstream -- ditto, downwards * groupup -- whether or not this node is in a group with the node upstream @@ -365,7 +385,7 @@ typedef struct Stream StreamPtr downstream; bool groupup; Cost groupcost; - Cost groupsel; + Selectivity groupsel; } Stream; #endif /* RELATION_H */ diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h index abde39b237c..c654b6953e7 100644 --- a/src/include/optimizer/cost.h +++ b/src/include/optimizer/cost.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: cost.h,v 1.24 1999/11/23 20:07:05 momjian Exp $ + * $Id: cost.h,v 1.25 2000/01/09 00:26:46 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -33,34 +33,28 @@ extern bool _enable_mergejoin_; extern bool _enable_hashjoin_; extern bool _enable_tidscan_; -extern Cost cost_seqscan(int relid, int relpages, int reltuples); -extern Cost cost_index(Oid indexid, int expected_indexpages, Cost selec, - int relpages, int reltuples, int indexpages, - int indextuples, bool is_injoin); -extern Cost cost_tidscan(List *evallist); -extern Cost cost_sort(List *pathkeys, int tuples, int width); -extern Cost cost_nestloop(Cost outercost, Cost innercost, int outertuples, - int innertuples, int outerpages, bool is_indexjoin); -extern Cost cost_mergejoin(Cost outercost, Cost innercost, - List *outersortkeys, List *innersortkeys, - int outersize, int innersize, int outerwidth, int innerwidth); -extern Cost cost_hashjoin(Cost outercost, Cost innercost, - int outersize, int innersize, - int outerwidth, int innerwidth, - Cost innerdisbursion); -extern int compute_rel_size(RelOptInfo *rel); -extern int compute_rel_width(RelOptInfo *rel); -extern int compute_joinrel_size(JoinPath *joinpath); -extern int page_size(int tuples, int width); +extern Cost cost_seqscan(RelOptInfo *baserel); +extern Cost cost_index(RelOptInfo *baserel, IndexOptInfo *index, + long expected_indexpages, Selectivity selec, + bool is_injoin); +extern Cost cost_tidscan(RelOptInfo *baserel, List *tideval); +extern Cost cost_sort(List *pathkeys, double tuples, int width); +extern Cost cost_nestloop(Path *outer_path, Path *inner_path, + bool is_indexjoin); +extern Cost cost_mergejoin(Path *outer_path, Path *inner_path, + List *outersortkeys, List *innersortkeys); +extern Cost cost_hashjoin(Path *outer_path, Path *inner_path, + Selectivity innerdisbursion); +extern void set_rel_rows_width(Query *root, RelOptInfo *rel); +extern void set_joinrel_rows_width(Query *root, RelOptInfo *rel, + JoinPath *joinpath); /* - * prototypes for fuctions in clausesel.h + * prototypes for clausesel.c * routines to compute clause selectivities */ -extern void set_clause_selectivities(List *restrictinfo_list, Cost new_selectivity); -extern Cost product_selec(List *restrictinfo_list); -extern void set_rest_relselec(Query *root, List *rel_list); -extern void set_rest_selec(Query *root, List *restrictinfo_list); -extern Cost compute_clause_selec(Query *root, Node *clause); +extern Selectivity restrictlist_selec(Query *root, List *restrictinfo_list); +extern Selectivity clauselist_selec(Query *root, List *clauses); +extern Selectivity compute_clause_selec(Query *root, Node *clause); #endif /* COST_H */ diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h index 2aca95e605d..25781a34476 100644 --- a/src/include/optimizer/pathnode.h +++ b/src/include/optimizer/pathnode.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pathnode.h,v 1.22 1999/11/23 20:07:06 momjian Exp $ + * $Id: pathnode.h,v 1.23 2000/01/09 00:26:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -21,26 +21,27 @@ extern bool path_is_cheaper(Path *path1, Path *path2); extern Path *set_cheapest(RelOptInfo *parent_rel, List *pathlist); extern List *add_pathlist(RelOptInfo *parent_rel, List *old_paths, - List *new_paths); + List *new_paths); extern Path *create_seqscan_path(RelOptInfo *rel); - extern IndexPath *create_index_path(Query *root, RelOptInfo *rel, - RelOptInfo *index, List *restriction_clauses); + IndexOptInfo *index, + List *restriction_clauses); extern TidPath *create_tidscan_path(RelOptInfo *rel, List *tideval); extern NestPath *create_nestloop_path(RelOptInfo *joinrel, - RelOptInfo *outer_rel, Path *outer_path, Path *inner_path, - List *pathkeys); - -extern MergePath *create_mergejoin_path(RelOptInfo *joinrel, int outersize, - int innersize, int outerwidth, int innerwidth, Path *outer_path, - Path *inner_path, List *pathkeys, - List *mergeclauses, List *outersortkeys, List *innersortkeys); - -extern HashPath *create_hashjoin_path(RelOptInfo *joinrel, int outersize, - int innersize, int outerwidth, int innerwidth, Path *outer_path, - Path *inner_path, List *hashclauses, Cost innerdisbursion); + Path *outer_path, Path *inner_path, + List *pathkeys); + +extern MergePath *create_mergejoin_path(RelOptInfo *joinrel, Path *outer_path, + Path *inner_path, List *pathkeys, + List *mergeclauses, + List *outersortkeys, + List *innersortkeys); + +extern HashPath *create_hashjoin_path(RelOptInfo *joinrel, Path *outer_path, + Path *inner_path, List *hashclauses, + Selectivity innerdisbursion); /* * prototypes for rel.c diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h index 92ce9f9719f..a3f6bad36be 100644 --- a/src/include/optimizer/paths.h +++ b/src/include/optimizer/paths.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: paths.h,v 1.36 1999/11/23 20:07:06 momjian Exp $ + * $Id: paths.h,v 1.37 2000/01/09 00:26:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -28,6 +28,8 @@ extern RelOptInfo *make_one_rel(Query *root, List *rels); extern List *create_index_paths(Query *root, RelOptInfo *rel, List *indices, List *restrictinfo_list, List *joininfo_list); +extern Oid indexable_operator(Expr *clause, Oid opclass, Oid relam, + bool indexkey_on_left); extern List *expand_indexqual_conditions(List *indexquals); /* @@ -65,7 +67,7 @@ extern bool pathkeys_contained_in(List *keys1, List *keys2); extern Path *get_cheapest_path_for_pathkeys(List *paths, List *pathkeys, bool indexpaths_only); extern List *build_index_pathkeys(Query *root, RelOptInfo *rel, - RelOptInfo *index); + IndexOptInfo *index); extern List *build_join_pathkeys(List *outer_pathkeys, List *join_rel_tlist, List *joinclauses); extern bool commute_pathkeys(List *pathkeys); @@ -93,7 +95,7 @@ extern bool is_subset(List *s1, List *s2); * prototypes for path/prune.c */ extern void merge_rels_with_same_relids(List *rel_list); -extern void rels_set_cheapest(List *rel_list); +extern void rels_set_cheapest(Query *root, List *rel_list); extern List *del_rels_all_bushy_inactive(List *old_rels); #endif /* PATHS_H */ diff --git a/src/include/optimizer/plancat.h b/src/include/optimizer/plancat.h index 34c853d68f8..307b51c3f42 100644 --- a/src/include/optimizer/plancat.h +++ b/src/include/optimizer/plancat.h @@ -6,36 +6,36 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: plancat.h,v 1.14 1999/11/21 23:25:42 tgl Exp $ + * $Id: plancat.h,v 1.15 2000/01/09 00:26:47 tgl Exp $ * *------------------------------------------------------------------------- */ #ifndef PLANCAT_H #define PLANCAT_H -#include "nodes/parsenodes.h" +#include "nodes/relation.h" extern void relation_info(Query *root, Index relid, - bool *hasindex, int *pages, int *tuples); + bool *hasindex, long *pages, double *tuples); extern List *find_secondary_indexes(Query *root, Index relid); -extern Cost restriction_selectivity(Oid functionObjectId, +extern List *find_inheritance_children(Oid inhparent); + +extern Selectivity restriction_selectivity(Oid functionObjectId, Oid operatorObjectId, Oid relationObjectId, AttrNumber attributeNumber, Datum constValue, int constFlag); -extern void index_selectivity(Query *root, int relid, Oid indexid, - List *indexquals, - float *idxPages, float *idxSelec); +extern void index_selectivity(Query *root, RelOptInfo *rel, + IndexOptInfo *index, List *indexquals, + long *idxPages, Selectivity *idxSelec); -extern Cost join_selectivity(Oid functionObjectId, Oid operatorObjectId, +extern Selectivity join_selectivity(Oid functionObjectId, Oid operatorObjectId, Oid relationObjectId1, AttrNumber attributeNumber1, Oid relationObjectId2, AttrNumber attributeNumber2); -extern List *find_inheritance_children(Oid inhparent); - #endif /* PLANCAT_H */ diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h index 8664fb9aaae..409559a6960 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: planmain.h,v 1.34 1999/10/07 04:23:19 tgl Exp $ + * $Id: planmain.h,v 1.35 2000/01/09 00:26:47 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -24,7 +24,7 @@ extern Plan *query_planner(Query *root, List *tlist, List *qual); /* * prototypes for plan/createplan.c */ -extern Plan *create_plan(Path *best_path); +extern Plan *create_plan(Query *root, Path *best_path); extern SeqScan *make_seqscan(List *qptlist, List *qpqual, Index scanrelid); extern Sort *make_sort(List *tlist, Oid nonameid, Plan *lefttree, int keycount); @@ -41,7 +41,6 @@ extern Result *make_result(List *tlist, Node *resconstantqual, Plan *subplan); extern void make_var_only_tlist(Query *root, List *tlist); extern void add_restrict_and_join_to_rels(Query *root, List *clauses); extern void add_missing_rels_to_query(Query *root); -extern void set_joininfo_mergeable_hashable(List *rel_list); /* * prototypes for plan/setrefs.c |