diff options
Diffstat (limited to 'src/backend/optimizer')
35 files changed, 833 insertions, 846 deletions
diff --git a/src/backend/optimizer/geqo/geqo_eval.c b/src/backend/optimizer/geqo/geqo_eval.c index cf52ddfc457..4d2df3373c6 100644 --- a/src/backend/optimizer/geqo/geqo_eval.c +++ b/src/backend/optimizer/geqo/geqo_eval.c @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: geqo_eval.c,v 1.23 1998/09/01 03:23:07 momjian Exp $ + * $Id: geqo_eval.c,v 1.24 1998/09/01 04:29:16 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -50,12 +50,12 @@ #include "optimizer/geqo_paths.h" -static List *gimme_clause_joins(Query *root, RelOptInfo *outer_rel, RelOptInfo *inner_rel); -static RelOptInfo *gimme_clauseless_join(RelOptInfo *outer_rel, RelOptInfo *inner_rel); -static RelOptInfo *init_join_rel(RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinInfo *joininfo); +static List *gimme_clause_joins(Query *root, RelOptInfo * outer_rel, RelOptInfo * inner_rel); +static RelOptInfo *gimme_clauseless_join(RelOptInfo * outer_rel, RelOptInfo * inner_rel); +static RelOptInfo *init_join_rel(RelOptInfo * outer_rel, RelOptInfo * inner_rel, JoinInfo * joininfo); static List *new_join_tlist(List *tlist, List *other_relids, int first_resdomno); static List *new_joininfo_list(List *joininfo_list, List *join_relids); -static void geqo_joinrel_size(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel); +static void geqo_joinrel_size(RelOptInfo * joinrel, RelOptInfo * outer_rel, RelOptInfo * inner_rel); static RelOptInfo *geqo_nth(int stop, List *rels); /* @@ -66,7 +66,7 @@ static RelOptInfo *geqo_nth(int stop, List *rels); Cost geqo_eval(Query *root, Gene *tour, int num_gene) { - RelOptInfo *joinrel; + RelOptInfo *joinrel; Cost fitness; List *temp; @@ -99,13 +99,13 @@ geqo_eval(Query *root, Gene *tour, int num_gene) * Returns a new join relation incorporating all joins in a left-sided tree. */ RelOptInfo * -gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo *outer_rel) +gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo * outer_rel) { - RelOptInfo *inner_rel; /* current relation */ + RelOptInfo *inner_rel; /* current relation */ int base_rel_index; List *new_rels = NIL; - RelOptInfo *new_rel = NULL; + RelOptInfo *new_rel = NULL; if (rel_count < num_gene) { /* tree not yet finished */ @@ -189,7 +189,7 @@ gimme_tree(Query *root, Gene *tour, int rel_count, int num_gene, RelOptInfo *out */ static List * -gimme_clause_joins(Query *root, RelOptInfo *outer_rel, RelOptInfo *inner_rel) +gimme_clause_joins(Query *root, RelOptInfo * outer_rel, RelOptInfo * inner_rel) { List *join_list = NIL; List *i = NIL; @@ -197,8 +197,8 @@ gimme_clause_joins(Query *root, RelOptInfo *outer_rel, RelOptInfo *inner_rel) foreach(i, joininfo_list) { - JoinInfo *joininfo = (JoinInfo *) lfirst(i); - RelOptInfo *rel = NULL; + JoinInfo *joininfo = (JoinInfo *) lfirst(i); + RelOptInfo *rel = NULL; if (!joininfo->inactive) { @@ -240,7 +240,7 @@ gimme_clause_joins(Query *root, RelOptInfo *outer_rel, RelOptInfo *inner_rel) */ static RelOptInfo * -gimme_clauseless_join(RelOptInfo *outer_rel, RelOptInfo *inner_rel) +gimme_clauseless_join(RelOptInfo * outer_rel, RelOptInfo * inner_rel) { return init_join_rel(outer_rel, inner_rel, (JoinInfo *) NULL); } @@ -257,9 +257,9 @@ gimme_clauseless_join(RelOptInfo *outer_rel, RelOptInfo *inner_rel) * Returns the new join relation node. */ static RelOptInfo * -init_join_rel(RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinInfo *joininfo) +init_join_rel(RelOptInfo * outer_rel, RelOptInfo * inner_rel, JoinInfo * joininfo) { - RelOptInfo *joinrel = makeNode(RelOptInfo); + RelOptInfo *joinrel = makeNode(RelOptInfo); List *joinrel_joininfo_list = NIL; List *new_outer_tlist; List *new_inner_tlist; @@ -389,13 +389,13 @@ new_joininfo_list(List *joininfo_list, List *join_relids) { List *current_joininfo_list = NIL; List *new_otherrels = NIL; - JoinInfo *other_joininfo = (JoinInfo *) NULL; + JoinInfo *other_joininfo = (JoinInfo *) NULL; List *xjoininfo = NIL; foreach(xjoininfo, joininfo_list) { List *or; - JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); + JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); new_otherrels = joininfo->otherrels; foreach(or, new_otherrels) @@ -457,16 +457,16 @@ geqo_add_new_joininfos(Query *root, List *joinrels, List *outerrels) List *xrel = NIL; List *xjoininfo = NIL; - RelOptInfo *rel; + RelOptInfo *rel; List *relids; List *super_rels; List *xsuper_rel = NIL; - JoinInfo *new_joininfo; + JoinInfo *new_joininfo; foreach(xjoinrel, joinrels) { - RelOptInfo *joinrel = (RelOptInfo *) lfirst(xjoinrel); + RelOptInfo *joinrel = (RelOptInfo *) lfirst(xjoinrel); foreach(xrelid, joinrel->relids) { @@ -477,8 +477,8 @@ geqo_add_new_joininfos(Query *root, List *joinrels, List *outerrels) */ /* - * ! BUG BUG ! Relid relid = (Relid)lfirst(xrelid); RelOptInfo *rel = - * get_join_rel(root, relid); + * ! BUG BUG ! Relid relid = (Relid)lfirst(xrelid); RelOptInfo + * *rel = get_join_rel(root, relid); */ /* @@ -502,11 +502,11 @@ geqo_add_new_joininfos(Query *root, List *joinrels, List *outerrels) } foreach(xjoinrel, joinrels) { - RelOptInfo *joinrel = (RelOptInfo *) lfirst(xjoinrel); + RelOptInfo *joinrel = (RelOptInfo *) lfirst(xjoinrel); foreach(xjoininfo, joinrel->joininfo) { - JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); + JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); List *other_rels = joininfo->otherrels; List *clause_info = joininfo->jinfoclauseinfo; bool mergejoinable = joininfo->mergejoinable; @@ -516,8 +516,8 @@ geqo_add_new_joininfos(Query *root, List *joinrels, List *outerrels) { /* - * ! BUG BUG ! Relid relid = (Relid)lfirst(xrelid); RelOptInfo - * *rel = get_join_rel(root, relid); + * ! BUG BUG ! Relid relid = (Relid)lfirst(xrelid); + * RelOptInfo *rel = get_join_rel(root, relid); */ /* @@ -549,12 +549,12 @@ geqo_add_new_joininfos(Query *root, List *joinrels, List *outerrels) foreach(xsuper_rel, super_rels) { - RelOptInfo *super_rel = (RelOptInfo *) lfirst(xsuper_rel); + RelOptInfo *super_rel = (RelOptInfo *) lfirst(xsuper_rel); if (nonoverlap_rels(super_rel, joinrel)) { List *new_relids = super_rel->relids; - JoinInfo *other_joininfo = + JoinInfo *other_joininfo = joininfo_member(new_relids, joinrel->joininfo); @@ -566,7 +566,7 @@ geqo_add_new_joininfos(Query *root, List *joinrels, List *outerrels) } else { - JoinInfo *new_joininfo = makeNode(JoinInfo); + JoinInfo *new_joininfo = makeNode(JoinInfo); new_joininfo->otherrels = new_relids; new_joininfo->jinfoclauseinfo = clause_info; @@ -611,13 +611,13 @@ geqo_final_join_rels(List *join_rel_list) */ foreach(xrel, join_rel_list) { - RelOptInfo *rel = (RelOptInfo *) lfirst(xrel); + RelOptInfo *rel = (RelOptInfo *) lfirst(xrel); List *xjoininfo = NIL; bool final = true; foreach(xjoininfo, rel->joininfo) { - JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); + JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); if (joininfo->otherrels != NIL) { @@ -645,7 +645,7 @@ geqo_final_join_rels(List *join_rel_list) * Modifies the superrels field of rel */ static void -add_superrels(RelOptInfo *rel, RelOptInfo *super_rel) +add_superrels(RelOptInfo * rel, RelOptInfo * super_rel) { rel->superrels = lappend(rel->superrels, super_rel); } @@ -660,7 +660,7 @@ add_superrels(RelOptInfo *rel, RelOptInfo *super_rel) * Returns non-nil if rel1 and rel2 do not overlap. */ static bool -nonoverlap_rels(RelOptInfo *rel1, RelOptInfo *rel2) +nonoverlap_rels(RelOptInfo * rel1, RelOptInfo * rel2) { return nonoverlap_sets(rel1->relids, rel2->relids); } @@ -680,7 +680,7 @@ nonoverlap_sets(List *s1, List *s2) return true; } -#endif /* NOTUSED */ +#endif /* NOTUSED */ /* * geqo_joinrel_size-- @@ -688,7 +688,7 @@ nonoverlap_sets(List *s1, List *s2) * long join queries; so get logarithm of size when MAXINT overflow; */ static void -geqo_joinrel_size(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel) +geqo_joinrel_size(RelOptInfo * joinrel, RelOptInfo * outer_rel, RelOptInfo * inner_rel) { Cost temp; int ntuples; diff --git a/src/backend/optimizer/geqo/geqo_main.c b/src/backend/optimizer/geqo/geqo_main.c index fd75985c40a..68b8f6245e1 100644 --- a/src/backend/optimizer/geqo/geqo_main.c +++ b/src/backend/optimizer/geqo/geqo_main.c @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: geqo_main.c,v 1.10 1998/09/01 03:23:09 momjian Exp $ + * $Id: geqo_main.c,v 1.11 1998/09/01 04:29:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -98,7 +98,7 @@ geqo(Query *root) status_interval; Gene *best_tour; - RelOptInfo *best_rel; + RelOptInfo *best_rel; /* Plan *best_plan; */ diff --git a/src/backend/optimizer/geqo/geqo_misc.c b/src/backend/optimizer/geqo/geqo_misc.c index c1dab6a99ca..e79b2138ea8 100644 --- a/src/backend/optimizer/geqo/geqo_misc.c +++ b/src/backend/optimizer/geqo/geqo_misc.c @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: geqo_misc.c,v 1.10 1998/09/01 03:23:10 momjian Exp $ + * $Id: geqo_misc.c,v 1.11 1998/09/01 04:29:19 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -146,7 +146,7 @@ geqo_print_joinclauses(Query *root, List *clauses) foreach(l, clauses) { - ClauseInfo *c = lfirst(l); + ClauseInfo *c = lfirst(l); print_expr((Node *) c->clause, root->rtable); if (lnext(l)) @@ -262,7 +262,7 @@ geqo_print_path(Query *root, Path *path, int indent) } void -geqo_print_rel(Query *root, RelOptInfo *rel) +geqo_print_rel(Query *root, RelOptInfo * rel) { List *l; diff --git a/src/backend/optimizer/geqo/geqo_paths.c b/src/backend/optimizer/geqo/geqo_paths.c index a23c9010de2..25928d167f8 100644 --- a/src/backend/optimizer/geqo/geqo_paths.c +++ b/src/backend/optimizer/geqo/geqo_paths.c @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: geqo_paths.c,v 1.11 1998/09/01 03:23:12 momjian Exp $ + * $Id: geqo_paths.c,v 1.12 1998/09/01 04:29:21 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -28,8 +28,8 @@ #include "optimizer/geqo_paths.h" -static List *geqo_prune_rel(RelOptInfo *rel, List *other_rels); -static Path *set_paths(RelOptInfo *rel, Path *unorderedpath); +static List *geqo_prune_rel(RelOptInfo * rel, List *other_rels); +static Path *set_paths(RelOptInfo * rel, Path *unorderedpath); /* * geqo-prune-rels-- @@ -47,8 +47,8 @@ geqo_prune_rels(List *rel_list) if (rel_list != NIL) { temp_list = lcons(lfirst(rel_list), - geqo_prune_rels(geqo_prune_rel((RelOptInfo *) lfirst(rel_list), - lnext(rel_list)))); + geqo_prune_rels(geqo_prune_rel((RelOptInfo *) lfirst(rel_list), + lnext(rel_list)))); } return temp_list; } @@ -65,12 +65,12 @@ geqo_prune_rels(List *rel_list) * */ static List * -geqo_prune_rel(RelOptInfo *rel, List *other_rels) +geqo_prune_rel(RelOptInfo * rel, List *other_rels) { List *i = NIL; List *t_list = NIL; List *temp_node = NIL; - RelOptInfo *other_rel = (RelOptInfo *) NULL; + RelOptInfo *other_rel = (RelOptInfo *) NULL; foreach(i, other_rels) { @@ -102,7 +102,7 @@ geqo_prune_rel(RelOptInfo *rel, List *other_rels) * */ void -geqo_rel_paths(RelOptInfo *rel) +geqo_rel_paths(RelOptInfo * rel) { List *y = NIL; Path *path = (Path *) NULL; @@ -134,7 +134,7 @@ geqo_rel_paths(RelOptInfo *rel) * */ static Path * -set_paths(RelOptInfo *rel, Path *unorderedpath) +set_paths(RelOptInfo * rel, Path *unorderedpath) { Path *cheapest = set_cheapest(rel, rel->pathlist); diff --git a/src/backend/optimizer/geqo/minspantree.c b/src/backend/optimizer/geqo/minspantree.c index c4e1b53ad00..41171fc5100 100644 --- a/src/backend/optimizer/geqo/minspantree.c +++ b/src/backend/optimizer/geqo/minspantree.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION -* $Header: /cvsroot/pgsql/src/backend/optimizer/geqo/Attic/minspantree.c,v 1.7 1998/08/10 02:26:19 momjian Exp $ +* $Header: /cvsroot/pgsql/src/backend/optimizer/geqo/Attic/minspantree.c,v 1.8 1998/09/01 04:29:24 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,7 @@ */ void -minspantree(Query *root, List *join_rels, RelOptInfo *garel) +minspantree(Query *root, List *join_rels, RelOptInfo * garel) { int number_of_rels = length(root->base_rel_list); int number_of_joins = length(join_rels); @@ -70,8 +70,8 @@ minspantree(Query *root, List *join_rels, RelOptInfo *garel) id1, id2; List *r = NIL; - RelOptInfo *joinrel = NULL; - RelOptInfo **tmprel_array; + RelOptInfo *joinrel = NULL; + RelOptInfo **tmprel_array; /* allocate memory for matrix tmprel_array[x][y] */ @@ -111,9 +111,9 @@ minspantree(Query *root, List *join_rels, RelOptInfo *garel) else if (number_of_joins == 3) { - RelOptInfo *rel12 = (RelOptInfo *) &tmprel_array[1][2]; - RelOptInfo *rel13 = (RelOptInfo *) &tmprel_array[1][3]; - RelOptInfo *rel23 = (RelOptInfo *) &tmprel_array[2][3]; + RelOptInfo *rel12 = (RelOptInfo *) & tmprel_array[1][2]; + RelOptInfo *rel13 = (RelOptInfo *) & tmprel_array[1][3]; + RelOptInfo *rel23 = (RelOptInfo *) & tmprel_array[2][3]; if (rel12->cheapestpath->path_cost > rel13->cheapestpath->path_cost) { @@ -159,9 +159,9 @@ minspantree(Query *root, List *join_rels, RelOptInfo *garel) if (connectto[tempn] != 0) { if (n > tempn) - joinrel = (RelOptInfo *) &tmprel_array[tempn][n]; + joinrel = (RelOptInfo *) & tmprel_array[tempn][n]; else - joinrel = (RelOptInfo *) &tmprel_array[n][tempn]; + joinrel = (RelOptInfo *) & tmprel_array[n][tempn]; dist = joinrel->cheapestpath->path_cost; if (dist < disttoconnect[tempn]) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 00b22c0abc2..8de364a04af 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.22 1998/09/01 03:23:17 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/allpaths.c,v 1.23 1998/09/01 04:29:27 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -45,8 +45,10 @@ int32 _use_geqo_rels_ = GEQO_RELS; static void find_rel_paths(Query *root, List *rels); static List *find_join_paths(Query *root, List *outer_rels, int levels_needed); + #ifdef OPTIMIZER_DEBUG -static void debug_print_rel(Query *root, RelOptInfo *rel); +static void debug_print_rel(Query *root, RelOptInfo * rel); + #endif /* @@ -76,6 +78,7 @@ find_paths(Query *root, List *rels) if (levels_needed <= 1) { + /* * Unsorted single relation, no more processing is required. */ @@ -83,6 +86,7 @@ find_paths(Query *root, List *rels) } else { + /* * this means that joins or sorts are required. set selectivities * of clauses that have not been set by an index. @@ -118,10 +122,10 @@ find_rel_paths(Query *root, List *rels) sequential_scan_list = lcons(create_seqscan_path(rel), NIL); rel_index_scan_list = find_index_paths(root, - rel, - find_relation_indices(root, rel), - rel->clauseinfo, - rel->joininfo); + rel, + find_relation_indices(root, rel), + rel->clauseinfo, + rel->joininfo); or_index_scan_list = create_or_index_paths(root, rel, rel->clauseinfo); @@ -180,7 +184,8 @@ find_join_paths(Query *root, List *outer_rels, int levels_needed) *******************************************/ if ((_use_geqo_) && length(root->base_rel_list) >= _use_geqo_rels_) - return lcons(geqo(root), NIL); /* returns *one* RelOptInfo, so lcons it */ + return lcons(geqo(root), NIL); /* returns *one* RelOptInfo, so + * lcons it */ /******************************************* * rest will be deprecated in case of GEQO * @@ -280,7 +285,7 @@ print_joinclauses(Query *root, List *clauses) foreach(l, clauses) { - ClauseInfo *c = lfirst(l); + ClauseInfo *c = lfirst(l); print_expr((Node *) c->clause, root->rtable); if (lnext(l)) @@ -396,7 +401,7 @@ print_path(Query *root, Path *path, int indent) } static void -debug_print_rel(Query *root, RelOptInfo *rel) +debug_print_rel(Query *root, RelOptInfo * rel) { List *l; @@ -412,4 +417,4 @@ debug_print_rel(Query *root, RelOptInfo *rel) print_path(root, rel->cheapestpath, 1); } -#endif /* OPTIMIZER_DEBUG */ +#endif /* OPTIMIZER_DEBUG */ diff --git a/src/backend/optimizer/path/clausesel.c b/src/backend/optimizer/path/clausesel.c index 94cc5c71fcf..8a0536c7bbe 100644 --- a/src/backend/optimizer/path/clausesel.c +++ b/src/backend/optimizer/path/clausesel.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.12 1998/09/01 03:23:19 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.13 1998/09/01 04:29:29 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -46,7 +46,7 @@ void set_clause_selectivities(List *clauseinfo_list, Cost new_selectivity) { List *temp; - ClauseInfo *clausenode; + ClauseInfo *clausenode; Cost cost_clause; foreach(temp, clauseinfo_list) @@ -95,7 +95,7 @@ product_selec(List *clauseinfo_list) void set_rest_relselec(Query *root, List *rel_list) { - RelOptInfo *rel; + RelOptInfo *rel; List *x; foreach(x, rel_list) @@ -117,7 +117,7 @@ void set_rest_selec(Query *root, List *clauseinfo_list) { List *temp = NIL; - ClauseInfo *clausenode = (ClauseInfo *) NULL; + ClauseInfo *clausenode = (ClauseInfo *) NULL; Cost cost_clause; foreach(temp, clauseinfo_list) @@ -159,8 +159,8 @@ set_rest_selec(Query *root, List *clauseinfo_list) Cost compute_clause_selec(Query *root, Node *clause, List *or_selectivities) { - if (is_opclause(clause)) - return compute_selec(root, lcons(clause,NIL), or_selectivities); + if (is_opclause(clause)) + return compute_selec(root, lcons(clause, NIL), or_selectivities); else if (not_clause(clause)) { @@ -182,9 +182,7 @@ compute_clause_selec(Query *root, Node *clause, List *or_selectivities) return compute_selec(root, ((Expr *) clause)->args, or_selectivities); } else - { return compute_selec(root, lcons(clause, NIL), or_selectivities); - } } /* diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 7d00a7f1f5c..5fbf3e5059f 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.24 1998/09/01 03:23:20 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.25 1998/09/01 04:29:30 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -360,7 +360,7 @@ cost_hashjoin(Cost outercost, * Returns the size. */ int -compute_rel_size(RelOptInfo *rel) +compute_rel_size(RelOptInfo * rel) { Cost temp; int temp1; @@ -383,7 +383,7 @@ compute_rel_size(RelOptInfo *rel) * Returns the width of the tuple as a fixnum. */ int -compute_rel_width(RelOptInfo *rel) +compute_rel_width(RelOptInfo * rel) { return compute_targetlist_width(get_actual_tlist(rel->targetlist)); } diff --git a/src/backend/optimizer/path/hashutils.c b/src/backend/optimizer/path/hashutils.c index 29ce0f67fce..59bf4897c0a 100644 --- a/src/backend/optimizer/path/hashutils.c +++ b/src/backend/optimizer/path/hashutils.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/hashutils.c,v 1.6 1998/09/01 03:23:22 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/hashutils.c,v 1.7 1998/09/01 04:29:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -39,7 +39,7 @@ group_clauses_by_hashop(List *clauseinfo_list, int inner_relid) { List *hashinfo_list = NIL; - ClauseInfo *clauseinfo = (ClauseInfo *) NULL; + ClauseInfo *clauseinfo = (ClauseInfo *) NULL; List *i = NIL; Oid hashjoinop = 0; @@ -121,7 +121,7 @@ match_hashop_hashinfo(Oid hashop, List *hashinfo_list) key = xhashinfo->hashop; if (hashop == key) { /* found */ - return xhashinfo; /* should be a hashinfo node ! */ + return xhashinfo; /* should be a hashinfo node ! */ } } return (HInfo *) NIL; diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 9d991d97aa1..24f46ec9331 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.33 1998/09/01 03:23:23 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.34 1998/09/01 04:29:33 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -41,46 +41,36 @@ #include "parser/parsetree.h" /* for getrelid() */ #include "parser/parse_expr.h" /* for exprType() */ #include "parser/parse_oper.h" /* for oprid() and oper() */ -#include "parser/parse_coerce.h" /* for IS_BINARY_COMPATIBLE() */ +#include "parser/parse_coerce.h"/* for IS_BINARY_COMPATIBLE() */ #include "utils/lsyscache.h" -static void -match_index_orclauses(RelOptInfo *rel, RelOptInfo *index, int indexkey, +static void match_index_orclauses(RelOptInfo * rel, RelOptInfo * index, int indexkey, int xclass, List *clauseinfo_list); -static bool -match_index_to_operand(int indexkey, Expr *operand, - RelOptInfo *rel, RelOptInfo *index); -static List * -match_index_orclause(RelOptInfo *rel, RelOptInfo *index, int indexkey, +static bool match_index_to_operand(int indexkey, Expr *operand, + RelOptInfo * rel, RelOptInfo * index); +static List *match_index_orclause(RelOptInfo * rel, RelOptInfo * index, int indexkey, int xclass, List *or_clauses, List *other_matching_indices); -static List * -group_clauses_by_indexkey(RelOptInfo *rel, RelOptInfo *index, +static List *group_clauses_by_indexkey(RelOptInfo * rel, RelOptInfo * index, int *indexkeys, Oid *classes, List *clauseinfo_list); -static List * -group_clauses_by_ikey_for_joins(RelOptInfo *rel, RelOptInfo *index, +static List *group_clauses_by_ikey_for_joins(RelOptInfo * rel, RelOptInfo * index, int *indexkeys, Oid *classes, List *join_cinfo_list, List *restr_cinfo_list); -static ClauseInfo * -match_clause_to_indexkey(RelOptInfo *rel, RelOptInfo *index, int indexkey, - int xclass, ClauseInfo *clauseInfo, bool join); -static bool -pred_test(List *predicate_list, List *clauseinfo_list, +static ClauseInfo *match_clause_to_indexkey(RelOptInfo * rel, RelOptInfo * index, int indexkey, + int xclass, ClauseInfo * clauseInfo, bool join); +static bool pred_test(List *predicate_list, List *clauseinfo_list, List *joininfo_list); static bool one_pred_test(Expr *predicate, List *clauseinfo_list); static bool one_pred_clause_expr_test(Expr *predicate, Node *clause); static bool one_pred_clause_test(Expr *predicate, Node *clause); static bool clause_pred_clause_test(Expr *predicate, Node *clause); -static List * -indexable_joinclauses(RelOptInfo *rel, RelOptInfo *index, +static List *indexable_joinclauses(RelOptInfo * rel, RelOptInfo * index, List *joininfo_list, List *clauseinfo_list); -static List * -index_innerjoin(Query *root, RelOptInfo *rel, - List *clausegroup_list, RelOptInfo *index); -static List * -create_index_paths(Query *root, RelOptInfo *rel, RelOptInfo *index, +static List *index_innerjoin(Query *root, RelOptInfo * rel, + List *clausegroup_list, RelOptInfo * index); +static List *create_index_paths(Query *root, RelOptInfo * rel, RelOptInfo * index, List *clausegroup_list, bool join); static List *add_index_paths(List *indexpaths, List *new_indexpaths); -static bool function_index_operand(Expr *funcOpnd, RelOptInfo *rel, RelOptInfo *index); +static bool function_index_operand(Expr *funcOpnd, RelOptInfo * rel, RelOptInfo * index); /* find_index_paths() @@ -110,14 +100,14 @@ static bool function_index_operand(Expr *funcOpnd, RelOptInfo *rel, RelOptInfo * */ List * find_index_paths(Query *root, - RelOptInfo *rel, + RelOptInfo * rel, List *indices, List *clauseinfo_list, List *joininfo_list) { List *scanclausegroups = NIL; List *scanpaths = NIL; - RelOptInfo *index = (RelOptInfo *) NULL; + RelOptInfo *index = (RelOptInfo *) NULL; List *joinclausegroups = NIL; List *joinpaths = NIL; List *retval = NIL; @@ -127,7 +117,10 @@ find_index_paths(Query *root, { index = (RelOptInfo *) lfirst(ilist); - /* If this is a partial index, return if it fails the predicate test */ + /* + * If this is a partial index, return if it fails the predicate + * test + */ if (index->indpred != NIL) if (!pred_test(index->indpred, clauseinfo_list, joininfo_list)) continue; @@ -136,20 +129,20 @@ find_index_paths(Query *root, * 1. Try matching the index against subclauses of an 'or' clause. * The fields of the clauseinfo nodes are marked with lists of the * matching indices. No path are actually created. We currently - * only look to match the first key. We don't find multi-key index - * cases where an AND matches the first key, and the OR matches the - * second key. + * only look to match the first key. We don't find multi-key + * index cases where an AND matches the first key, and the OR + * matches the second key. */ match_index_orclauses(rel, - index, - index->indexkeys[0], - index->classlist[0], - clauseinfo_list); + index, + index->indexkeys[0], + index->classlist[0], + clauseinfo_list); /* - * 2. If the keys of this index match any of the available restriction - * clauses, then create pathnodes corresponding to each group of - * usable clauses. + * 2. If the keys of this index match any of the available + * restriction clauses, then create pathnodes corresponding to + * each group of usable clauses. */ scanclausegroups = group_clauses_by_indexkey(rel, index, @@ -167,10 +160,10 @@ find_index_paths(Query *root, /* * 3. If this index can be used with any join clause, then create - * pathnodes for each group of usable clauses. An index can be used - * with a join clause if its ordering is useful for a mergejoin, or if - * the index can possibly be used for scanning the inner relation of a - * nestloop join. + * pathnodes for each group of usable clauses. An index can be + * used with a join clause if its ordering is useful for a + * mergejoin, or if the index can possibly be used for scanning + * the inner relation of a nestloop join. */ joinclausegroups = indexable_joinclauses(rel, index, joininfo_list, clauseinfo_list); joinpaths = NIL; @@ -179,7 +172,7 @@ find_index_paths(Query *root, { List *new_join_paths = create_index_paths(root, rel, index, - joinclausegroups, + joinclausegroups, true); List *innerjoin_paths = index_innerjoin(root, rel, joinclausegroups, index); @@ -225,13 +218,13 @@ find_index_paths(Query *root, * */ static void -match_index_orclauses(RelOptInfo *rel, - RelOptInfo *index, +match_index_orclauses(RelOptInfo * rel, + RelOptInfo * index, int indexkey, int xclass, List *clauseinfo_list) { - ClauseInfo *clauseinfo = (ClauseInfo *) NULL; + ClauseInfo *clauseinfo = (ClauseInfo *) NULL; List *i = NIL; foreach(i, clauseinfo_list) @@ -262,10 +255,10 @@ match_index_orclauses(RelOptInfo *rel, static bool match_index_to_operand(int indexkey, Expr *operand, - RelOptInfo *rel, - RelOptInfo *index) + RelOptInfo * rel, + RelOptInfo * index) { - bool result; + bool result; /* * Normal index. @@ -305,8 +298,8 @@ match_index_to_operand(int indexkey, * match the third, g,h match the fourth, etc. */ static List * -match_index_orclause(RelOptInfo *rel, - RelOptInfo *index, +match_index_orclause(RelOptInfo * rel, + RelOptInfo * index, int indexkey, int xclass, List *or_clauses, @@ -323,30 +316,29 @@ match_index_orclause(RelOptInfo *rel, foreach(clist, or_clauses) matching_indices = lcons(NIL, matching_indices); } - else matching_indices = other_matching_indices; + else + matching_indices = other_matching_indices; index_list = matching_indices; foreach(clist, or_clauses) { clause = lfirst(clist); - + if (is_opclause(clause) && op_class(((Oper *) ((Expr *) clause)->oper)->opno, xclass, index->relam) && ((match_index_to_operand(indexkey, - (Expr *) get_leftop((Expr *) clause), - rel, - index) && + (Expr *) get_leftop((Expr *) clause), + rel, + index) && IsA(get_rightop((Expr *) clause), Const)) || (match_index_to_operand(indexkey, (Expr *) get_rightop((Expr *) clause), - rel, - index) && - IsA(get_leftop((Expr *) clause), Const)))) - { + rel, + index) && + IsA(get_leftop((Expr *) clause), Const)))) lfirst(matching_indices) = lcons(index, lfirst(matching_indices)); - } matching_indices = lnext(matching_indices); } @@ -396,14 +388,14 @@ match_index_orclause(RelOptInfo *rel, * */ static List * -group_clauses_by_indexkey(RelOptInfo *rel, - RelOptInfo *index, +group_clauses_by_indexkey(RelOptInfo * rel, + RelOptInfo * index, int *indexkeys, Oid *classes, List *clauseinfo_list) { List *curCinfo = NIL; - ClauseInfo *matched_clause = (ClauseInfo *) NULL; + ClauseInfo *matched_clause = (ClauseInfo *) NULL; List *clausegroup = NIL; int curIndxKey; Oid curClass; @@ -420,7 +412,7 @@ group_clauses_by_indexkey(RelOptInfo *rel, foreach(curCinfo, clauseinfo_list) { - ClauseInfo *temp = (ClauseInfo *) lfirst(curCinfo); + ClauseInfo *temp = (ClauseInfo *) lfirst(curCinfo); matched_clause = match_clause_to_indexkey(rel, index, @@ -458,15 +450,15 @@ group_clauses_by_indexkey(RelOptInfo *rel, * */ static List * -group_clauses_by_ikey_for_joins(RelOptInfo *rel, - RelOptInfo *index, +group_clauses_by_ikey_for_joins(RelOptInfo * rel, + RelOptInfo * index, int *indexkeys, Oid *classes, List *join_cinfo_list, List *restr_cinfo_list) { List *curCinfo = NIL; - ClauseInfo *matched_clause = (ClauseInfo *) NULL; + ClauseInfo *matched_clause = (ClauseInfo *) NULL; List *clausegroup = NIL; int curIndxKey; Oid curClass; @@ -484,7 +476,7 @@ group_clauses_by_ikey_for_joins(RelOptInfo *rel, foreach(curCinfo, join_cinfo_list) { - ClauseInfo *temp = (ClauseInfo *) lfirst(curCinfo); + ClauseInfo *temp = (ClauseInfo *) lfirst(curCinfo); matched_clause = match_clause_to_indexkey(rel, index, @@ -500,7 +492,7 @@ group_clauses_by_ikey_for_joins(RelOptInfo *rel, } foreach(curCinfo, restr_cinfo_list) { - ClauseInfo *temp = (ClauseInfo *) lfirst(curCinfo); + ClauseInfo *temp = (ClauseInfo *) lfirst(curCinfo); matched_clause = match_clause_to_indexkey(rel, index, @@ -580,11 +572,11 @@ group_clauses_by_ikey_for_joins(RelOptInfo *rel, * */ static ClauseInfo * -match_clause_to_indexkey(RelOptInfo *rel, - RelOptInfo *index, +match_clause_to_indexkey(RelOptInfo * rel, + RelOptInfo * index, int indexkey, int xclass, - ClauseInfo *clauseInfo, + ClauseInfo * clauseInfo, bool join) { Expr *clause = clauseInfo->clause; @@ -607,6 +599,7 @@ match_clause_to_indexkey(RelOptInfo *rel, */ if (!join) { + /* * Check for standard s-argable clause */ @@ -622,24 +615,28 @@ match_clause_to_indexkey(RelOptInfo *rel, index)); #ifndef IGNORE_BINARY_COMPATIBLE_INDICES - /* Didn't find an index? - * Then maybe we can find another binary-compatible index instead... - * thomas 1998-08-14 + + /* + * Didn't find an index? Then maybe we can find another + * binary-compatible index instead... thomas 1998-08-14 */ - if (! isIndexable) + if (!isIndexable) { - Oid ltype; - Oid rtype; + Oid ltype; + Oid rtype; - ltype = exprType((Node *)leftop); - rtype = exprType((Node *)rightop); + ltype = exprType((Node *) leftop); + rtype = exprType((Node *) rightop); - /* make sure we have two different binary-compatible types... */ + /* + * make sure we have two different binary-compatible + * types... + */ if ((ltype != rtype) - && IS_BINARY_COMPATIBLE(ltype, rtype)) + && IS_BINARY_COMPATIBLE(ltype, rtype)) { - char *opname; - Operator newop; + char *opname; + Operator newop; opname = get_opname(restrict_op); if (opname != NULL) @@ -660,9 +657,7 @@ match_clause_to_indexkey(RelOptInfo *rel, index)); if (isIndexable) - { ((Oper *) ((Expr *) clause)->oper)->opno = restrict_op; - } } } } @@ -679,24 +674,24 @@ match_clause_to_indexkey(RelOptInfo *rel, get_commutator(((Oper *) ((Expr *) clause)->oper)->opno); isIndexable = ((restrict_op != InvalidOid) && - op_class(restrict_op, xclass, index->relam) && - IndexScanableOperand(rightop, - indexkey, rel, index)); + op_class(restrict_op, xclass, index->relam) && + IndexScanableOperand(rightop, + indexkey, rel, index)); #ifndef IGNORE_BINARY_COMPATIBLE_INDICES - if (! isIndexable) + if (!isIndexable) { - Oid ltype; - Oid rtype; + Oid ltype; + Oid rtype; - ltype = exprType((Node *)leftop); - rtype = exprType((Node *)rightop); + ltype = exprType((Node *) leftop); + rtype = exprType((Node *) rightop); if ((ltype != rtype) - && IS_BINARY_COMPATIBLE(ltype, rtype)) + && IS_BINARY_COMPATIBLE(ltype, rtype)) { - char *opname; - Operator newop; + char *opname; + Operator newop; restrict_op = ((Oper *) ((Expr *) clause)->oper)->opno; @@ -712,16 +707,14 @@ match_clause_to_indexkey(RelOptInfo *rel, get_commutator(oprid(newop)); isIndexable = ((restrict_op != InvalidOid) && - op_class(restrict_op, xclass, index->relam) && - IndexScanableOperand(rightop, - indexkey, - rel, - index)); + op_class(restrict_op, xclass, index->relam) && + IndexScanableOperand(rightop, + indexkey, + rel, + index)); if (isIndexable) - { ((Oper *) ((Expr *) clause)->oper)->opno = oprid(newop); - } } } } @@ -729,6 +722,7 @@ match_clause_to_indexkey(RelOptInfo *rel, if (isIndexable) { + /* * In place list modification. (op const var/func) -> (op * var/func const) @@ -848,7 +842,7 @@ pred_test(List *predicate_list, List *clauseinfo_list, List *joininfo_list) static bool one_pred_test(Expr *predicate, List *clauseinfo_list) { - ClauseInfo *clauseinfo; + ClauseInfo *clauseinfo; List *item; Assert(predicate != NULL); @@ -1152,7 +1146,7 @@ clause_pred_clause_test(Expr *predicate, Node *clause) */ test_oper = makeOper(test_op, /* opno */ InvalidOid, /* opid */ - BOOLOID, /* opresulttype */ + BOOLOID, /* opresulttype */ 0, /* opsize */ NULL); /* op_fcache */ replace_opid(test_oper); @@ -1163,7 +1157,7 @@ clause_pred_clause_test(Expr *predicate, Node *clause) #ifndef OMIT_PARTIAL_INDEX test_result = ExecEvalExpr((Node *) test_expr, NULL, &isNull, NULL); -#endif /* OMIT_PARTIAL_INDEX */ +#endif /* OMIT_PARTIAL_INDEX */ if (isNull) { elog(DEBUG, "clause_pred_clause_test: null test result"); @@ -1193,10 +1187,10 @@ clause_pred_clause_test(Expr *predicate, Node *clause) * */ static List * -indexable_joinclauses(RelOptInfo *rel, RelOptInfo *index, +indexable_joinclauses(RelOptInfo * rel, RelOptInfo * index, List *joininfo_list, List *clauseinfo_list) { - JoinInfo *joininfo = (JoinInfo *) NULL; + JoinInfo *joininfo = (JoinInfo *) NULL; List *cg_list = NIL; List *i = NIL; List *clausegroups = NIL; @@ -1245,7 +1239,7 @@ extract_restrict_clauses(List *clausegroup) foreach(l, clausegroup) { - ClauseInfo *cinfo = lfirst(l); + ClauseInfo *cinfo = lfirst(l); if (!is_joinable((Node *) cinfo->clause)) restrict_cls = lappend(restrict_cls, cinfo); @@ -1267,8 +1261,8 @@ extract_restrict_clauses(List *clausegroup) * */ static List * -index_innerjoin(Query *root, RelOptInfo *rel, List *clausegroup_list, - RelOptInfo *index) +index_innerjoin(Query *root, RelOptInfo * rel, List *clausegroup_list, + RelOptInfo * index) { List *clausegroup = NIL; List *cg_list = NIL; @@ -1354,8 +1348,8 @@ index_innerjoin(Query *root, RelOptInfo *rel, List *clausegroup_list, */ static List * create_index_paths(Query *root, - RelOptInfo *rel, - RelOptInfo *index, + RelOptInfo * rel, + RelOptInfo * index, List *clausegroup_list, bool join) { @@ -1367,7 +1361,7 @@ create_index_paths(Query *root, foreach(i, clausegroup_list) { - ClauseInfo *clauseinfo; + ClauseInfo *clauseinfo; List *temp_node = NIL; bool temp = true; @@ -1399,7 +1393,7 @@ add_index_paths(List *indexpaths, List *new_indexpaths) } static bool -function_index_operand(Expr *funcOpnd, RelOptInfo *rel, RelOptInfo *index) +function_index_operand(Expr *funcOpnd, RelOptInfo * rel, RelOptInfo * index) { Oid heapRelid = (Oid) lfirsti(rel->relids); Func *function; diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c index 7b05f9fddfc..f8291f7e964 100644 --- a/src/backend/optimizer/path/joinpath.c +++ b/src/backend/optimizer/path/joinpath.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.9 1998/09/01 03:23:24 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinpath.c,v 1.10 1998/09/01 04:29:35 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -30,19 +30,15 @@ * _enable_mergejoin} */ static Path *best_innerjoin(List *join_paths, List *outer_relid); -static List * -sort_inner_and_outer(RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, +static List *sort_inner_and_outer(RelOptInfo * joinrel, RelOptInfo * outerrel, RelOptInfo * innerrel, List *mergeinfo_list); -static List * -match_unsorted_outer(RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, +static List *match_unsorted_outer(RelOptInfo * joinrel, RelOptInfo * outerrel, RelOptInfo * innerrel, List *outerpath_list, Path *cheapest_inner, Path *best_innerjoin, List *mergeinfo_list); -static List * -match_unsorted_inner(RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, +static List *match_unsorted_inner(RelOptInfo * joinrel, RelOptInfo * outerrel, RelOptInfo * innerrel, List *innerpath_list, List *mergeinfo_list); -static bool EnoughMemoryForHashjoin(RelOptInfo *hashrel); -static List * -hash_inner_and_outer(RelOptInfo *joinrel, RelOptInfo *outerrel, RelOptInfo *innerrel, +static bool EnoughMemoryForHashjoin(RelOptInfo * hashrel); +static List *hash_inner_and_outer(RelOptInfo * joinrel, RelOptInfo * outerrel, RelOptInfo * innerrel, List *hashinfo_list); /* @@ -76,11 +72,11 @@ find_all_join_paths(Query *root, List *joinrels) while (joinrels != NIL) { - RelOptInfo *joinrel = (RelOptInfo *) lfirst(joinrels); + RelOptInfo *joinrel = (RelOptInfo *) lfirst(joinrels); List *innerrelids; List *outerrelids; - RelOptInfo *innerrel; - RelOptInfo *outerrel; + RelOptInfo *innerrel; + RelOptInfo *outerrel; Path *bestinnerjoin; List *pathlist = NIL; @@ -238,9 +234,9 @@ best_innerjoin(List *join_paths, List *outer_relids) * Returns a list of mergejoin paths. */ static List * -sort_inner_and_outer(RelOptInfo *joinrel, - RelOptInfo *outerrel, - RelOptInfo *innerrel, +sort_inner_and_outer(RelOptInfo * joinrel, + RelOptInfo * outerrel, + RelOptInfo * innerrel, List *mergeinfo_list) { List *ms_list = NIL; @@ -316,9 +312,9 @@ sort_inner_and_outer(RelOptInfo *joinrel, * Returns a list of possible join path nodes. */ static List * -match_unsorted_outer(RelOptInfo *joinrel, - RelOptInfo *outerrel, - RelOptInfo *innerrel, +match_unsorted_outer(RelOptInfo * joinrel, + RelOptInfo * outerrel, + RelOptInfo * innerrel, List *outerpath_list, Path *cheapest_inner, Path *best_innerjoin, @@ -469,9 +465,9 @@ match_unsorted_outer(RelOptInfo *joinrel, * Returns a list of possible merge paths. */ static List * -match_unsorted_inner(RelOptInfo *joinrel, - RelOptInfo *outerrel, - RelOptInfo *innerrel, +match_unsorted_inner(RelOptInfo * joinrel, + RelOptInfo * outerrel, + RelOptInfo * innerrel, List *innerpath_list, List *mergeinfo_list) { @@ -565,7 +561,7 @@ match_unsorted_inner(RelOptInfo *joinrel, } static bool -EnoughMemoryForHashjoin(RelOptInfo *hashrel) +EnoughMemoryForHashjoin(RelOptInfo * hashrel) { int ntuples; int tupsize; @@ -599,9 +595,9 @@ EnoughMemoryForHashjoin(RelOptInfo *hashrel) * Returns a list of hashjoin paths. */ static List * -hash_inner_and_outer(RelOptInfo *joinrel, - RelOptInfo *outerrel, - RelOptInfo *innerrel, +hash_inner_and_outer(RelOptInfo * joinrel, + RelOptInfo * outerrel, + RelOptInfo * innerrel, List *hashinfo_list) { HInfo *xhashinfo = (HInfo *) NULL; diff --git a/src/backend/optimizer/path/joinrels.c b/src/backend/optimizer/path/joinrels.c index 2a0755010d6..636207c9410 100644 --- a/src/backend/optimizer/path/joinrels.c +++ b/src/backend/optimizer/path/joinrels.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.14 1998/09/01 03:23:25 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/joinrels.c,v 1.15 1998/09/01 04:29:37 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,19 +31,17 @@ bool _use_right_sided_plans_ = false; #endif -static List *find_clause_joins(Query *root, RelOptInfo *outer_rel, List *joininfo_list); -static List *find_clauseless_joins(RelOptInfo *outer_rel, List *inner_rels); -static RelOptInfo *init_join_rel(RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinInfo *joininfo); -static List * -new_join_tlist(List *tlist, List *other_relids, +static List *find_clause_joins(Query *root, RelOptInfo * outer_rel, List *joininfo_list); +static List *find_clauseless_joins(RelOptInfo * outer_rel, List *inner_rels); +static RelOptInfo *init_join_rel(RelOptInfo * outer_rel, RelOptInfo * inner_rel, JoinInfo * joininfo); +static List *new_join_tlist(List *tlist, List *other_relids, int first_resdomno); static List *new_joininfo_list(List *joininfo_list, List *join_relids); -static void add_superrels(RelOptInfo *rel, RelOptInfo *super_rel); -static bool nonoverlap_rels(RelOptInfo *rel1, RelOptInfo *rel2); +static void add_superrels(RelOptInfo * rel, RelOptInfo * super_rel); +static bool nonoverlap_rels(RelOptInfo * rel1, RelOptInfo * rel2); static bool nonoverlap_sets(List *s1, List *s2); -static void -set_joinrel_size(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, - JoinInfo *jinfo); +static void set_joinrel_size(RelOptInfo * joinrel, RelOptInfo * outer_rel, RelOptInfo * inner_rel, + JoinInfo * jinfo); /* * find-join-rels-- @@ -67,7 +65,7 @@ find_join_rels(Query *root, List *outer_rels) foreach(r, outer_rels) { - RelOptInfo *outer_rel = (RelOptInfo *) lfirst(r); + RelOptInfo *outer_rel = (RelOptInfo *) lfirst(r); if (!(joins = find_clause_joins(root, outer_rel, outer_rel->joininfo))) { @@ -99,15 +97,15 @@ find_join_rels(Query *root, List *outer_rels) * Returns a list of new join relations. */ static List * -find_clause_joins(Query *root, RelOptInfo *outer_rel, List *joininfo_list) +find_clause_joins(Query *root, RelOptInfo * outer_rel, List *joininfo_list) { List *join_list = NIL; List *i = NIL; foreach(i, joininfo_list) { - JoinInfo *joininfo = (JoinInfo *) lfirst(i); - RelOptInfo *rel; + JoinInfo *joininfo = (JoinInfo *) lfirst(i); + RelOptInfo *rel; if (!joininfo->inactive) { @@ -158,9 +156,9 @@ find_clause_joins(Query *root, RelOptInfo *outer_rel, List *joininfo_list) * Returns a list of new join relations. */ static List * -find_clauseless_joins(RelOptInfo *outer_rel, List *inner_rels) +find_clauseless_joins(RelOptInfo * outer_rel, List *inner_rels) { - RelOptInfo *inner_rel; + RelOptInfo *inner_rel; List *t_list = NIL; List *temp_node = NIL; List *i = NIL; @@ -193,9 +191,9 @@ find_clauseless_joins(RelOptInfo *outer_rel, List *inner_rels) * Returns the new join relation node. */ static RelOptInfo * -init_join_rel(RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinInfo *joininfo) +init_join_rel(RelOptInfo * outer_rel, RelOptInfo * inner_rel, JoinInfo * joininfo) { - RelOptInfo *joinrel = makeNode(RelOptInfo); + RelOptInfo *joinrel = makeNode(RelOptInfo); List *joinrel_joininfo_list = NIL; List *new_outer_tlist; List *new_inner_tlist; @@ -327,13 +325,13 @@ new_joininfo_list(List *joininfo_list, List *join_relids) { List *current_joininfo_list = NIL; List *new_otherrels = NIL; - JoinInfo *other_joininfo = (JoinInfo *) NULL; + JoinInfo *other_joininfo = (JoinInfo *) NULL; List *xjoininfo = NIL; foreach(xjoininfo, joininfo_list) { List *or; - JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); + JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); new_otherrels = joininfo->otherrels; foreach(or, new_otherrels) @@ -396,23 +394,23 @@ add_new_joininfos(Query *root, List *joinrels, List *outerrels) foreach(xjoinrel, joinrels) { - RelOptInfo *joinrel = (RelOptInfo *) lfirst(xjoinrel); + RelOptInfo *joinrel = (RelOptInfo *) lfirst(xjoinrel); foreach(xrelid, joinrel->relids) { Relid relid = (Relid) lfirst(xrelid); - RelOptInfo *rel = get_join_rel(root, relid); + RelOptInfo *rel = get_join_rel(root, relid); add_superrels(rel, joinrel); } } foreach(xjoinrel, joinrels) { - RelOptInfo *joinrel = (RelOptInfo *) lfirst(xjoinrel); + RelOptInfo *joinrel = (RelOptInfo *) lfirst(xjoinrel); foreach(xjoininfo, joinrel->joininfo) { - JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); + JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); List *other_rels = joininfo->otherrels; List *clause_info = joininfo->jinfoclauseinfo; bool mergejoinable = joininfo->mergejoinable; @@ -421,10 +419,10 @@ add_new_joininfos(Query *root, List *joinrels, List *outerrels) foreach(xrelid, other_rels) { Relid relid = (Relid) lfirst(xrelid); - RelOptInfo *rel = get_join_rel(root, relid); + RelOptInfo *rel = get_join_rel(root, relid); List *super_rels = rel->superrels; List *xsuper_rel = NIL; - JoinInfo *new_joininfo = makeNode(JoinInfo); + JoinInfo *new_joininfo = makeNode(JoinInfo); new_joininfo->otherrels = joinrel->relids; new_joininfo->jinfoclauseinfo = clause_info; @@ -436,12 +434,12 @@ add_new_joininfos(Query *root, List *joinrels, List *outerrels) foreach(xsuper_rel, super_rels) { - RelOptInfo *super_rel = (RelOptInfo *) lfirst(xsuper_rel); + RelOptInfo *super_rel = (RelOptInfo *) lfirst(xsuper_rel); if (nonoverlap_rels(super_rel, joinrel)) { List *new_relids = super_rel->relids; - JoinInfo *other_joininfo = + JoinInfo *other_joininfo = joininfo_member(new_relids, joinrel->joininfo); @@ -453,7 +451,7 @@ add_new_joininfos(Query *root, List *joinrels, List *outerrels) } else { - JoinInfo *new_joininfo = makeNode(JoinInfo); + JoinInfo *new_joininfo = makeNode(JoinInfo); new_joininfo->otherrels = new_relids; new_joininfo->jinfoclauseinfo = clause_info; @@ -471,7 +469,7 @@ add_new_joininfos(Query *root, List *joinrels, List *outerrels) } foreach(xrel, outerrels) { - RelOptInfo *rel = (RelOptInfo *) lfirst(xrel); + RelOptInfo *rel = (RelOptInfo *) lfirst(xrel); rel->superrels = NIL; } @@ -499,13 +497,13 @@ final_join_rels(List *join_rel_list) */ foreach(xrel, join_rel_list) { - RelOptInfo *rel = (RelOptInfo *) lfirst(xrel); + RelOptInfo *rel = (RelOptInfo *) lfirst(xrel); List *xjoininfo = NIL; bool final = true; foreach(xjoininfo, rel->joininfo) { - JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); + JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); if (joininfo->otherrels != NIL) { @@ -533,7 +531,7 @@ final_join_rels(List *join_rel_list) * Modifies the superrels field of rel */ static void -add_superrels(RelOptInfo *rel, RelOptInfo *super_rel) +add_superrels(RelOptInfo * rel, RelOptInfo * super_rel) { rel->superrels = lappend(rel->superrels, super_rel); } @@ -548,7 +546,7 @@ add_superrels(RelOptInfo *rel, RelOptInfo *super_rel) * Returns non-nil if rel1 and rel2 do not overlap. */ static bool -nonoverlap_rels(RelOptInfo *rel1, RelOptInfo *rel2) +nonoverlap_rels(RelOptInfo * rel1, RelOptInfo * rel2) { return nonoverlap_sets(rel1->relids, rel2->relids); } @@ -569,7 +567,7 @@ nonoverlap_sets(List *s1, List *s2) } static void -set_joinrel_size(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, JoinInfo *jinfo) +set_joinrel_size(RelOptInfo * joinrel, RelOptInfo * outer_rel, RelOptInfo * inner_rel, JoinInfo * jinfo) { int ntuples; float selec; diff --git a/src/backend/optimizer/path/joinutils.c b/src/backend/optimizer/path/joinutils.c index f39a783547d..3b0bce83941 100644 --- a/src/backend/optimizer/path/joinutils.c +++ b/src/backend/optimizer/path/joinutils.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.7 1998/09/01 03:23:27 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/joinutils.c,v 1.8 1998/09/01 04:29:38 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -26,18 +26,14 @@ #include "optimizer/ordering.h" -static int -match_pathkey_joinkeys(List *pathkey, List *joinkeys, +static int match_pathkey_joinkeys(List *pathkey, List *joinkeys, int which_subkey); -static bool -every_func(List *joinkeys, List *pathkey, +static bool every_func(List *joinkeys, List *pathkey, int which_subkey); -static List * -new_join_pathkey(List *subkeys, +static List *new_join_pathkey(List *subkeys, List *considered_subkeys, List *join_rel_tlist, List *joinclauses); -static List * -new_matching_subkeys(Var *subkey, List *considered_subkeys, +static List *new_matching_subkeys(Var *subkey, List *considered_subkeys, List *join_rel_tlist, List *joinclauses); /**************************************************************************** @@ -146,7 +142,7 @@ match_pathkey_joinkeys(List *pathkey, pos++; } } - return -1; /* no index found */ + return -1; /* no index found */ } /* diff --git a/src/backend/optimizer/path/mergeutils.c b/src/backend/optimizer/path/mergeutils.c index 8bf4bb73c2c..2d1d0215112 100644 --- a/src/backend/optimizer/path/mergeutils.c +++ b/src/backend/optimizer/path/mergeutils.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/mergeutils.c,v 1.8 1998/09/01 03:23:28 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/mergeutils.c,v 1.9 1998/09/01 04:29:40 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -42,7 +42,7 @@ group_clauses_by_order(List *clauseinfo_list, foreach(xclauseinfo, clauseinfo_list) { - ClauseInfo *clauseinfo = (ClauseInfo *) lfirst(xclauseinfo); + ClauseInfo *clauseinfo = (ClauseInfo *) lfirst(xclauseinfo); MergeOrder *merge_ordering = clauseinfo->mergejoinorder; if (merge_ordering) diff --git a/src/backend/optimizer/path/orindxpath.c b/src/backend/optimizer/path/orindxpath.c index c56d6200f84..3f8d6b15daf 100644 --- a/src/backend/optimizer/path/orindxpath.c +++ b/src/backend/optimizer/path/orindxpath.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.10 1998/09/01 03:23:29 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/orindxpath.c,v 1.11 1998/09/01 04:29:41 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -32,11 +32,10 @@ static void -best_or_subclause_indices(Query *root, RelOptInfo *rel, List *subclauses, +best_or_subclause_indices(Query *root, RelOptInfo * rel, List *subclauses, List *indices, List *examined_indexids, Cost subcost, List *selectivities, List **indexids, Cost *cost, List **selecs); -static void -best_or_subclause_index(Query *root, RelOptInfo *rel, Expr *subclause, +static void best_or_subclause_index(Query *root, RelOptInfo * rel, Expr *subclause, List *indices, int *indexid, Cost *cost, Cost *selec); @@ -52,14 +51,14 @@ best_or_subclause_index(Query *root, RelOptInfo *rel, Expr *subclause, */ List * create_or_index_paths(Query *root, - RelOptInfo *rel, List *clauses) + RelOptInfo * rel, List *clauses) { List *t_list = NIL; List *clist; foreach(clist, clauses) { - ClauseInfo *clausenode = (ClauseInfo *) (lfirst(clist)); + ClauseInfo *clausenode = (ClauseInfo *) (lfirst(clist)); /* * Check to see if this clause is an 'or' clause, and, if so, @@ -114,8 +113,8 @@ create_or_index_paths(Query *root, * processing -- JMH, 7/7/92 */ pathnode->path.locclauseinfo = - set_difference(copyObject((Node *)rel->clauseinfo), - lcons(clausenode,NIL)); + set_difference(copyObject((Node *) rel->clauseinfo), + lcons(clausenode, NIL)); #if 0 /* fix xfunc */ /* add in cost for expensive functions! -- JMH, 7/7/92 */ @@ -156,7 +155,7 @@ create_or_index_paths(Query *root, */ static void best_or_subclause_indices(Query *root, - RelOptInfo *rel, + RelOptInfo * rel, List *subclauses, List *indices, List *examined_indexids, @@ -166,9 +165,9 @@ best_or_subclause_indices(Query *root, Cost *cost, /* return value */ List **selecs) /* return value */ { - List *slist; - - foreach (slist, subclauses) + List *slist; + + foreach(slist, subclauses) { int best_indexid; Cost best_cost; @@ -176,7 +175,7 @@ best_or_subclause_indices(Query *root, best_or_subclause_index(root, rel, lfirst(slist), lfirst(indices), &best_indexid, &best_cost, &best_selec); - + examined_indexids = lappendi(examined_indexids, best_indexid); subcost += best_cost; selectivities = lappend(selectivities, makeFloat(best_selec)); @@ -207,25 +206,25 @@ best_or_subclause_indices(Query *root, */ static void best_or_subclause_index(Query *root, - RelOptInfo *rel, + RelOptInfo * rel, Expr *subclause, List *indices, int *retIndexid, /* return value */ Cost *retCost, /* return value */ Cost *retSelec) /* return value */ { - List *ilist; - bool first_run = true; + List *ilist; + bool first_run = true; /* if we don't match anything, return zeros */ *retIndexid = 0; *retCost = 0.0; *retSelec = 0.0; - - foreach (ilist, indices) + + foreach(ilist, indices) { - RelOptInfo *index = (RelOptInfo *) lfirst(ilist); - + RelOptInfo *index = (RelOptInfo *) lfirst(ilist); + Datum value; int flag = 0; Cost subcost; diff --git a/src/backend/optimizer/path/predmig.c b/src/backend/optimizer/path/predmig.c index 07615c031d5..b1ff33cee63 100644 --- a/src/backend/optimizer/path/predmig.c +++ b/src/backend/optimizer/path/predmig.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/predmig.c,v 1.12 1998/09/01 03:23:30 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/predmig.c,v 1.13 1998/09/01 04:29:42 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -53,21 +53,18 @@ * (not a join) iff it has * a non-NULL cinfo field */ -static void -xfunc_predmig(JoinPath pathnode, Stream streamroot, +static void xfunc_predmig(JoinPath pathnode, Stream streamroot, Stream laststream, bool *progressp); static bool xfunc_series_llel(Stream stream); static bool xfunc_llel_chains(Stream root, Stream bottom); static Stream xfunc_complete_stream(Stream stream); -static bool -xfunc_prdmig_pullup(Stream origstream, Stream pullme, +static bool xfunc_prdmig_pullup(Stream origstream, Stream pullme, JoinPath joinpath); static void xfunc_form_groups(Stream root, Stream bottom); static void xfunc_free_stream(Stream root); static Stream xfunc_add_clauses(Stream current); static void xfunc_setup_group(Stream node, Stream bottom); -static Stream -xfunc_streaminsert(ClauseInfo clauseinfo, Stream current, +static Stream xfunc_streaminsert(ClauseInfo clauseinfo, Stream current, int clausetype); static int xfunc_num_relids(Stream node); static StreamPtr xfunc_get_downjoin(Stream node); @@ -77,7 +74,7 @@ static int xfunc_stream_compare(void *arg1, void *arg2); static bool xfunc_check_stream(Stream node); static bool xfunc_in_stream(Stream node, Stream stream); -/* ----------------- MAIN FUNCTIONS ------------------------ */ +/* ----------------- MAIN FUNCTIONS ------------------------ */ /* ** xfunc_do_predmig ** wrapper for Predicate Migration. It calls xfunc_predmig until no @@ -318,7 +315,7 @@ xfunc_complete_stream(Stream stream) static bool xfunc_prdmig_pullup(Stream origstream, Stream pullme, JoinPath joinpath) { - ClauseInfo clauseinfo = get_cinfo(pullme); + ClauseInfo clauseinfo = get_cinfo(pullme); bool progress = false; Stream upjoin, orignode, @@ -492,7 +489,7 @@ xfunc_form_groups(Query *queryInfo, Stream root, Stream bottom) } -/* ------------------- UTILITY FUNCTIONS ------------------------- */ +/* ------------------- UTILITY FUNCTIONS ------------------------- */ /* ** xfunc_free_stream -- diff --git a/src/backend/optimizer/path/prune.c b/src/backend/optimizer/path/prune.c index 18228cbd89f..908687e6d84 100644 --- a/src/backend/optimizer/path/prune.c +++ b/src/backend/optimizer/path/prune.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.16 1998/09/01 03:23:32 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.17 1998/09/01 04:29:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -24,7 +24,7 @@ #include "utils/elog.h" -static List *prune_joinrel(RelOptInfo *rel, List *other_rels); +static List *prune_joinrel(RelOptInfo * rel, List *other_rels); /* * prune-joinrels-- @@ -59,15 +59,15 @@ prune_joinrels(List *rel_list) * */ static List * -prune_joinrel(RelOptInfo *rel, List *other_rels) +prune_joinrel(RelOptInfo * rel, List *other_rels) { List *i = NIL; List *result = NIL; foreach(i, other_rels) { - RelOptInfo *other_rel = (RelOptInfo *) lfirst(i); - + RelOptInfo *other_rel = (RelOptInfo *) lfirst(i); + if (same(rel->relids, other_rel->relids)) { rel->pathlist = add_pathlist(rel, @@ -96,7 +96,7 @@ prune_rel_paths(List *rel_list) List *x = NIL; List *y = NIL; Path *path = NULL; - RelOptInfo *rel = (RelOptInfo *) NULL; + RelOptInfo *rel = (RelOptInfo *) NULL; JoinPath *cheapest = (JoinPath *) NULL; foreach(x, rel_list) @@ -130,7 +130,7 @@ prune_rel_paths(List *rel_list) * */ Path * -prune_rel_path(RelOptInfo *rel, Path *unorderedpath) +prune_rel_path(RelOptInfo * rel, Path *unorderedpath) { Path *cheapest = set_cheapest(rel, rel->pathlist); @@ -165,7 +165,7 @@ merge_joinrels(List *rel_list1, List *rel_list2) foreach(xrel, rel_list1) { - RelOptInfo *rel = (RelOptInfo *) lfirst(xrel); + RelOptInfo *rel = (RelOptInfo *) lfirst(xrel); rel_list2 = prune_joinrel(rel, rel_list2); } @@ -187,7 +187,7 @@ merge_joinrels(List *rel_list1, List *rel_list2) List * prune_oldrels(List *old_rels) { - RelOptInfo *rel; + RelOptInfo *rel; List *joininfo_list, *xjoininfo, *i, @@ -204,7 +204,7 @@ prune_oldrels(List *old_rels) { foreach(xjoininfo, joininfo_list) { - JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); + JoinInfo *joininfo = (JoinInfo *) lfirst(xjoininfo); if (!joininfo->inactive) { diff --git a/src/backend/optimizer/path/xfunc.c b/src/backend/optimizer/path/xfunc.c index b5eb9f2bdd5..f32b77cdc2a 100644 --- a/src/backend/optimizer/path/xfunc.c +++ b/src/backend/optimizer/path/xfunc.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.21 1998/09/01 03:23:33 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/xfunc.c,v 1.22 1998/09/01 04:29:45 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,8 +43,7 @@ #define ever ; 1 ; /* local funcs */ -static int -xfunc_card_unreferenced(Query *queryInfo, +static int xfunc_card_unreferenced(Query *queryInfo, Expr *clause, Relid referenced); */ @@ -60,8 +59,8 @@ void xfunc_trypullup(RelOptInfo rel) { LispValue y; /* list ptr */ - ClauseInfo maxcinfo; /* The ClauseInfo to pull up, as calculated by - * xfunc_shouldpull() */ + ClauseInfo maxcinfo; /* The ClauseInfo to pull up, as + * calculated by xfunc_shouldpull() */ JoinPath curpath; /* current path in list */ int progress; /* has progress been made this time * through? */ @@ -147,12 +146,12 @@ xfunc_shouldpull(Query *queryInfo, Path childpath, JoinPath parentpath, int whichchild, - ClauseInfo *maxcinfopt) /* Out: pointer to clause to - * pullup */ + ClauseInfo * maxcinfopt) /* Out: pointer to clause + * to pullup */ { LispValue clauselist, tmplist; /* lists of clauses */ - ClauseInfo maxcinfo; /* clause to pullup */ + ClauseInfo maxcinfo; /* clause to pullup */ LispValue primjoinclause /* primary join clause */ = xfunc_primary_join(parentpath); Cost tmprank, @@ -194,7 +193,7 @@ xfunc_shouldpull(Query *queryInfo, { if (tmplist != LispNil && - (tmprank = xfunc_rank(get_clause((ClauseInfo) lfirst(tmplist)))) + (tmprank = xfunc_rank(get_clause((ClauseInfo) lfirst(tmplist)))) > maxrank) { maxcinfo = (ClauseInfo) lfirst(tmplist); @@ -267,15 +266,15 @@ ClauseInfo xfunc_pullup(Query *queryInfo, Path childpath, JoinPath parentpath, - ClauseInfo cinfo, /* clause to pull up */ + ClauseInfo cinfo, /* clause to pull up */ int whichchild, /* whether child is INNER or OUTER of join */ int clausetype) /* whether clause to pull is join or local */ { Path newkid; - RelOptInfo newrel; + RelOptInfo newrel; Cost pulled_selec; Cost cost; - ClauseInfo newinfo; + ClauseInfo newinfo; /* remove clause from childpath */ newkid = (Path) copyObject((Node) childpath); @@ -294,8 +293,8 @@ xfunc_pullup(Query *queryInfo, } /* - * * give the new child path its own RelOptInfo node that reflects the * lack - * of the pulled-up predicate + * * give the new child path its own RelOptInfo node that reflects the * + * lack of the pulled-up predicate */ pulled_selec = compute_clause_selec(queryInfo, get_clause(cinfo), LispNil); @@ -497,8 +496,8 @@ xfunc_func_expense(LispValue node, LispValue args) /* look up tuple in cache */ tupl = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(funcid), - 0, 0, 0); + ObjectIdGetDatum(funcid), + 0, 0, 0); if (!HeapTupleIsValid(tupl)) elog(ERROR, "Cache lookup failed for procedure %d", funcid); proc = (Form_pg_proc) GETSTRUCT(tupl); @@ -528,7 +527,7 @@ xfunc_func_expense(LispValue node, LispValue args) if (nargs > 0) argOidVect = proc->proargtypes; planlist = (List) pg_parse_and_plan(pq_src, argOidVect, nargs, - &parseTree_list, None, FALSE); + &parseTree_list, None, FALSE); if (IsA(node, Func)) set_func_planlist((Func) node, planlist); @@ -612,7 +611,7 @@ xfunc_width(LispValue clause) { /* base case: width is width of this attribute */ tupl = SearchSysCacheTuple(TYPOID, - ObjectIdGetDatum(get_vartype((Var) clause)), + ObjectIdGetDatum(get_vartype((Var) clause)), 0, 0, 0); if (!HeapTupleIsValid(tupl)) elog(ERROR, "Cache lookup failed for type %d", @@ -682,8 +681,8 @@ xfunc_width(LispValue clause) elog(ERROR, "Cache lookup failed for procedure %d", get_opno((Oper) get_op(clause))); return (xfunc_func_width - ((RegProcedure) (((Form_pg_operator) (GETSTRUCT(tupl)))->oprcode), - (LispValue) get_opargs(clause))); + ((RegProcedure) (((Form_pg_operator) (GETSTRUCT(tupl)))->oprcode), + (LispValue) get_opargs(clause))); } else if (fast_is_funcclause(clause)) { @@ -740,7 +739,7 @@ xfunc_card_unreferenced(Query *queryInfo, { Assert(lnext(get_relids((RelOptInfo) lfirst(temp))) == LispNil); allrelids = lappend(allrelids, - lfirst(get_relids((RelOptInfo) lfirst(temp)))); + lfirst(get_relids((RelOptInfo) lfirst(temp)))); } /* find all relids referenced in query but not in clause */ @@ -760,7 +759,7 @@ xfunc_card_product(Query *queryInfo, Relid relids) { LispValue cinfonode; LispValue temp; - RelOptInfo currel; + RelOptInfo currel; Cost tuples; Count retval = 0; @@ -777,7 +776,7 @@ xfunc_card_product(Query *queryInfo, Relid relids) if (!xfunc_expense(queryInfo, get_clause((ClauseInfo) lfirst(cinfonode)))) tuples *= compute_clause_selec(queryInfo, - get_clause((ClauseInfo) lfirst(cinfonode)), + get_clause((ClauseInfo) lfirst(cinfonode)), LispNil); } @@ -863,7 +862,7 @@ LispValue xfunc_primary_join(JoinPath pathnode) { LispValue joinclauselist = get_pathclauseinfo(pathnode); - ClauseInfo mincinfo; + ClauseInfo mincinfo; LispValue tmplist; LispValue minclause = LispNil; Cost minrank, @@ -945,7 +944,7 @@ xfunc_get_path_cost(Query *queryInfo, Path pathnode) cost += (Cost) (xfunc_local_expense(get_clause((ClauseInfo) lfirst(tmplist))) * (Cost) get_tuples(get_parent(pathnode)) * selec); selec *= compute_clause_selec(queryInfo, - get_clause((ClauseInfo) lfirst(tmplist)), + get_clause((ClauseInfo) lfirst(tmplist)), LispNil); } @@ -966,7 +965,7 @@ xfunc_get_path_cost(Query *queryInfo, Path pathnode) cost += (Cost) (xfunc_local_expense(get_clause((ClauseInfo) lfirst(tmplist))) * (Cost) get_tuples(get_parent(pathnode)) * selec); selec *= compute_clause_selec(queryInfo, - get_clause((ClauseInfo) lfirst(tmplist)), + get_clause((ClauseInfo) lfirst(tmplist)), LispNil); } } @@ -1097,8 +1096,8 @@ xfunc_total_path_cost(JoinPath pathnode) Cost xfunc_expense_per_tuple(JoinPath joinnode, int whichchild) { - RelOptInfo outerrel = get_parent((Path) get_outerjoinpath(joinnode)); - RelOptInfo innerrel = get_parent((Path) get_innerjoinpath(joinnode)); + RelOptInfo outerrel = get_parent((Path) get_outerjoinpath(joinnode)); + RelOptInfo innerrel = get_parent((Path) get_innerjoinpath(joinnode)); Count outerwidth = get_width(outerrel); Count outers_per_page = ceil(BLCKSZ / (outerwidth + sizeof(HeapTupleData))); @@ -1139,7 +1138,7 @@ xfunc_expense_per_tuple(JoinPath joinnode, int whichchild) */ void xfunc_fixvars(LispValue clause, /* clause being pulled up */ - RelOptInfo rel, /* rel it's being pulled from */ + RelOptInfo rel, /* rel it's being pulled from */ int varno) /* whether rel is INNER or OUTER of join */ { LispValue tmpclause; /* temporary variable */ @@ -1195,8 +1194,8 @@ xfunc_fixvars(LispValue clause, /* clause being pulled up */ int xfunc_cinfo_compare(void *arg1, void *arg2) { - ClauseInfo info1 = *(ClauseInfo *) arg1; - ClauseInfo info2 = *(ClauseInfo *) arg2; + ClauseInfo info1 = *(ClauseInfo *) arg1; + ClauseInfo info2 = *(ClauseInfo *) arg2; LispValue clause1 = (LispValue) get_clause(info1), clause2 = (LispValue) get_clause(info2); @@ -1310,8 +1309,8 @@ xfunc_func_width(RegProcedure funcid, LispValue args) /* lookup function and find its return type */ Assert(RegProcedureIsValid(funcid)); tupl = SearchSysCacheTuple(PROOID, - ObjectIdGetDatum(funcid), - 0, 0, 0); + ObjectIdGetDatum(funcid), + 0, 0, 0); if (!HeapTupleIsValid(tupl)) elog(ERROR, "Cache lookup failed for procedure %d", funcid); proc = (Form_pg_proc) GETSTRUCT(tupl); @@ -1430,9 +1429,9 @@ do { \ ** Just like _copyRel, but doesn't copy the paths */ bool -xfunc_copyrel(RelOptInfo from, RelOptInfo *to) +xfunc_copyrel(RelOptInfo from, RelOptInfo * to) { - RelOptInfo newnode; + RelOptInfo newnode; Pointer (*alloc) () = palloc; diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 5011d0b2487..8eba20fd68c 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.31 1998/09/01 03:23:35 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.32 1998/09/01 04:29:47 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -46,44 +46,33 @@ static List *switch_outer(List *clauses); static Scan *create_scan_node(Path *best_path, List *tlist); static Join *create_join_node(JoinPath *best_path, List *tlist); -static SeqScan * -create_seqscan_node(Path *best_path, List *tlist, +static SeqScan *create_seqscan_node(Path *best_path, List *tlist, List *scan_clauses); -static IndexScan * -create_indexscan_node(IndexPath *best_path, List *tlist, +static IndexScan *create_indexscan_node(IndexPath *best_path, List *tlist, List *scan_clauses); -static NestLoop * -create_nestloop_node(JoinPath *best_path, List *tlist, +static NestLoop *create_nestloop_node(JoinPath *best_path, List *tlist, List *clauses, Plan *outer_node, List *outer_tlist, Plan *inner_node, List *inner_tlist); -static MergeJoin * -create_mergejoin_node(MergePath *best_path, List *tlist, +static MergeJoin *create_mergejoin_node(MergePath *best_path, List *tlist, List *clauses, Plan *outer_node, List *outer_tlist, Plan *inner_node, List *inner_tlist); -static HashJoin * -create_hashjoin_node(HashPath *best_path, List *tlist, +static HashJoin *create_hashjoin_node(HashPath *best_path, List *tlist, List *clauses, Plan *outer_node, List *outer_tlist, Plan *inner_node, List *inner_tlist); static Node *fix_indxqual_references(Node *clause, Path *index_path); -static Temp * -make_temp(List *tlist, List *keys, Oid *operators, +static Temp *make_temp(List *tlist, List *keys, Oid *operators, Plan *plan_node, int temptype); -static IndexScan * -make_indexscan(List *qptlist, List *qpqual, Index scanrelid, +static IndexScan *make_indexscan(List *qptlist, List *qpqual, Index scanrelid, List *indxid, List *indxqual, Cost cost); -static NestLoop * -make_nestloop(List *qptlist, List *qpqual, Plan *lefttree, +static NestLoop *make_nestloop(List *qptlist, List *qpqual, Plan *lefttree, Plan *righttree); -static HashJoin * -make_hashjoin(List *tlist, List *qpqual, +static HashJoin *make_hashjoin(List *tlist, List *qpqual, List *hashclauses, Plan *lefttree, Plan *righttree); static Hash *make_hash(List *tlist, Var *hashkey, Plan *lefttree); -static MergeJoin * -make_mergejoin(List *tlist, List *qpqual, +static MergeJoin *make_mergejoin(List *tlist, List *qpqual, List *mergeclauses, Oid opcode, Oid *rightorder, Oid *leftorder, Plan *righttree, Plan *lefttree); -static Material * -make_material(List *tlist, Oid tempid, Plan *lefttree, +static Material *make_material(List *tlist, Oid tempid, Plan *lefttree, int keycount); /* @@ -106,7 +95,7 @@ create_plan(Path *best_path) { List *tlist; Plan *plan_node = (Plan *) NULL; - RelOptInfo *parent_rel; + RelOptInfo *parent_rel; int size; int width; int pages; diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index 22cfeaf7557..85253b5c58c 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.19 1998/09/01 03:23:36 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/initsplan.c,v 1.20 1998/09/01 04:29:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -40,8 +40,8 @@ extern int Quiet; static void add_clause_to_rels(Query *root, List *clause); -static void add_join_info_to_rels(Query *root, ClauseInfo *clauseinfo, - List *join_relids); +static void add_join_info_to_rels(Query *root, ClauseInfo * clauseinfo, + List *join_relids); static void add_vars_to_targetlist(Query *root, List *vars, List *join_relids); static MergeOrder *mergejoinop(Expr *clause); @@ -170,7 +170,7 @@ add_clause_to_rels(Query *root, List *clause) { List *relids; List *vars; - ClauseInfo *clauseinfo = makeNode(ClauseInfo); + ClauseInfo *clauseinfo = makeNode(ClauseInfo); /* * Retrieve all relids and vars contained within the clause. @@ -199,6 +199,7 @@ add_clause_to_rels(Query *root, List *clause) */ if (is_funcclause((Node *) clause)) { + /* * XXX If we have a func clause set selectivity to 1/3, really * need a true selectivity function. @@ -222,6 +223,7 @@ add_clause_to_rels(Query *root, List *clause) if (is_funcclause((Node *) clause)) { + /* * XXX If we have a func clause set selectivity to 1/3, really * need a true selectivity function. @@ -252,13 +254,13 @@ add_clause_to_rels(Query *root, List *clause) * */ static void -add_join_info_to_rels(Query *root, ClauseInfo *clauseinfo, List *join_relids) +add_join_info_to_rels(Query *root, ClauseInfo * clauseinfo, List *join_relids) { List *join_relid; foreach(join_relid, join_relids) { - JoinInfo *joininfo; + JoinInfo *joininfo; List *other_rels = NIL; List *rel; @@ -269,7 +271,7 @@ add_join_info_to_rels(Query *root, ClauseInfo *clauseinfo, List *join_relids) } joininfo = find_joininfo_node(get_base_rel(root, lfirsti(join_relid)), - other_rels); + other_rels); joininfo->jinfoclauseinfo = lcons(copyObject((void *) clauseinfo), joininfo->jinfoclauseinfo); @@ -332,8 +334,8 @@ init_join_info(List *rel_list) *y, *z; RelOptInfo *rel; - JoinInfo *joininfo; - ClauseInfo *clauseinfo; + JoinInfo *joininfo; + ClauseInfo *clauseinfo; Expr *clause; foreach(x, rel_list) diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index a3e97063a79..0cef5472f29 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.27 1998/09/01 03:23:38 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.28 1998/09/01 04:29:51 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -44,8 +44,7 @@ static Plan *subplanner(Query *root, List *flat_tlist, List *qual); static Result *make_result(List *tlist, Node *resconstantqual, Plan *subplan); -extern Plan * -make_groupPlan(List **tlist, bool tuplePerGroup, +extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup, List *groupClause, Plan *subplan); /* @@ -90,7 +89,7 @@ query_planner(Query *root, printf("After cnfify()\n"); pprint(qual); #endif - + /* * A command without a target list or qualification is an error, * except for "delete foo". @@ -191,8 +190,8 @@ query_planner(Query *root, if (constant_qual) { subplan = (Plan *) make_result((!root->hasAggs && - !root->groupClause && - !root->havingQual) + !root->groupClause && + !root->havingQual) ? tlist : subplan->targetlist, (Node *) constant_qual, subplan); @@ -255,13 +254,13 @@ subplanner(Query *root, List *flat_tlist, List *qual) { - RelOptInfo *final_rel; - List *final_rel_list; + RelOptInfo *final_rel; + List *final_rel_list; /* * Initialize the targetlist and qualification, adding entries to - * base_rel_list as relation references are found (e.g., in - * the qualification, the targetlist, etc.) + * base_rel_list as relation references are found (e.g., in the + * qualification, the targetlist, etc.) */ root->base_rel_list = NIL; root->join_rel_list = NIL; diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 703e067e4cf..7d4091c4aa0 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.31 1998/09/01 03:23:39 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.32 1998/09/01 04:29:53 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -49,8 +49,7 @@ #include "executor/executor.h" static Plan *make_sortplan(List *tlist, List *sortcls, Plan *plannode); -extern Plan * -make_groupPlan(List **tlist, bool tuplePerGroup, +extern Plan *make_groupPlan(List **tlist, bool tuplePerGroup, List *groupClause, Plan *subplan); /***************************************************************************** @@ -96,10 +95,12 @@ union_planner(Query *parse) { List *tlist = parse->targetList; - /* copy the original tlist, we will need the original one - * for the AGG node later on */ - List *new_tlist = new_unsorted_tlist(tlist); - + /* + * copy the original tlist, we will need the original one for the AGG + * node later on + */ + List *new_tlist = new_unsorted_tlist(tlist); + List *rangetable = parse->rtable; Plan *result_plan = (Plan *) NULL; @@ -109,12 +110,12 @@ union_planner(Query *parse) if (parse->unionClause) { - result_plan = (Plan *) plan_union_queries(parse); - /* XXX do we need to do this? bjm 12/19/97 */ - tlist = preprocess_targetlist(tlist, - parse->commandType, - parse->resultRelation, - parse->rtable); + result_plan = (Plan *) plan_union_queries(parse); + /* XXX do we need to do this? bjm 12/19/97 */ + tlist = preprocess_targetlist(tlist, + parse->commandType, + parse->resultRelation, + parse->rtable); } else if ((rt_index = first_inherit_rt_entry(rangetable)) != -1) @@ -122,64 +123,65 @@ union_planner(Query *parse) result_plan = (Plan *) plan_inherit_queries(parse, rt_index); /* XXX do we need to do this? bjm 12/19/97 */ tlist = preprocess_targetlist(tlist, - parse->commandType, - parse->resultRelation, - parse->rtable); + parse->commandType, + parse->resultRelation, + parse->rtable); } else { - List **vpm = NULL; - - /* This is only necessary if aggregates are in use in queries like: - * SELECT sid - * FROM part - * GROUP BY sid - * HAVING MIN(pid) > 1; (pid is used but never selected for!!!) - * because the function 'query_planner' creates the plan for the lefttree - * of the 'GROUP' node and returns only those attributes contained in 'tlist'. - * The original 'tlist' contains only 'sid' here and that's why we have to - * to extend it to attributes which are not selected but are used in the - * havingQual. */ - - /* 'check_having_qual_for_vars' takes the havingQual and the actual 'tlist' - * as arguments and recursively scans the havingQual for attributes - * (VAR nodes) that are not contained in 'tlist' yet. If so, it creates - * a new entry and attaches it to the list 'new_tlist' (consisting of the - * VAR node and the RESDOM node as usual with tlists :-) ) */ - if (parse->hasAggs) - { - if (parse->havingQual != NULL) + List **vpm = NULL; + + /* + * This is only necessary if aggregates are in use in queries + * like: SELECT sid FROM part GROUP BY sid HAVING MIN(pid) > 1; + * (pid is used but never selected for!!!) because the function + * 'query_planner' creates the plan for the lefttree of the + * 'GROUP' node and returns only those attributes contained in + * 'tlist'. The original 'tlist' contains only 'sid' here and + * that's why we have to to extend it to attributes which are not + * selected but are used in the havingQual. + */ + + /* + * 'check_having_qual_for_vars' takes the havingQual and the + * actual 'tlist' as arguments and recursively scans the + * havingQual for attributes (VAR nodes) that are not contained in + * 'tlist' yet. If so, it creates a new entry and attaches it to + * the list 'new_tlist' (consisting of the VAR node and the RESDOM + * node as usual with tlists :-) ) + */ + if (parse->hasAggs) { - new_tlist = check_having_qual_for_vars(parse->havingQual,new_tlist); + if (parse->havingQual != NULL) + new_tlist = check_having_qual_for_vars(parse->havingQual, new_tlist); } - } - - new_tlist = preprocess_targetlist(new_tlist, - parse->commandType, - parse->resultRelation, - parse->rtable); - - /* Here starts the original (pre having) code */ - tlist = preprocess_targetlist(tlist, - parse->commandType, - parse->resultRelation, - parse->rtable); - - if (parse->rtable != NULL) - { - vpm = (List **) palloc(length(parse->rtable) * sizeof(List *)); - memset(vpm, 0, length(parse->rtable) * sizeof(List *)); - } - PlannerVarParam = lcons(vpm, PlannerVarParam); - result_plan = query_planner(parse, - parse->commandType, - new_tlist, - (List *) parse->qual); - PlannerVarParam = lnext(PlannerVarParam); - if (vpm != NULL) - pfree(vpm); + + new_tlist = preprocess_targetlist(new_tlist, + parse->commandType, + parse->resultRelation, + parse->rtable); + + /* Here starts the original (pre having) code */ + tlist = preprocess_targetlist(tlist, + parse->commandType, + parse->resultRelation, + parse->rtable); + + if (parse->rtable != NULL) + { + vpm = (List **) palloc(length(parse->rtable) * sizeof(List *)); + memset(vpm, 0, length(parse->rtable) * sizeof(List *)); + } + PlannerVarParam = lcons(vpm, PlannerVarParam); + result_plan = query_planner(parse, + parse->commandType, + new_tlist, + (List *) parse->qual); + PlannerVarParam = lnext(PlannerVarParam); + if (vpm != NULL) + pfree(vpm); } - + /* * If we have a GROUP BY clause, insert a group node (with the * appropriate sort node.) @@ -209,11 +211,14 @@ union_planner(Query *parse) */ if (parse->hasAggs) { - int old_length=0, new_length=0; - - /* Create the AGG node but use 'tlist' not 'new_tlist' as target list because we - * don't want the additional attributes (only used for the havingQual, see above) - * to show up in the result */ + int old_length = 0, + new_length = 0; + + /* + * Create the AGG node but use 'tlist' not 'new_tlist' as target + * list because we don't want the additional attributes (only used + * for the havingQual, see above) to show up in the result + */ result_plan = (Plan *) make_agg(tlist, result_plan); /* @@ -221,70 +226,84 @@ union_planner(Query *parse) * the result tuple of the subplans. */ ((Agg *) result_plan)->aggs = - set_agg_tlist_references((Agg *) result_plan); + set_agg_tlist_references((Agg *) result_plan); - if(parse->havingQual!=NULL) - { - List *clause; - List **vpm = NULL; - - - /* stuff copied from above to handle the use of attributes from outside - * in subselects */ + if (parse->havingQual != NULL) + { + List *clause; + List **vpm = NULL; + + + /* + * stuff copied from above to handle the use of attributes + * from outside in subselects + */ + + if (parse->rtable != NULL) + { + vpm = (List **) palloc(length(parse->rtable) * sizeof(List *)); + memset(vpm, 0, length(parse->rtable) * sizeof(List *)); + } + PlannerVarParam = lcons(vpm, PlannerVarParam); + + /* + * There is a subselect in the havingQual, so we have to + * process it using the same function as for a subselect in + * 'where' + */ + if (parse->hasSubLinks) + parse->havingQual = SS_process_sublinks((Node *) parse->havingQual); + + /* convert the havingQual to conjunctive normal form (cnf) */ + parse->havingQual = (Node *) cnfify((Expr *) (Node *) parse->havingQual, true); + + /* + * Calculate the opfids from the opnos (=select the correct + * functions for the used VAR datatypes) + */ + parse->havingQual = (Node *) fix_opids((List *) parse->havingQual); + + ((Agg *) result_plan)->plan.qual = (List *) parse->havingQual; + + /* + * Check every clause of the havingQual for aggregates used + * and append them to result_plan->aggs + */ + foreach(clause, ((Agg *) result_plan)->plan.qual) + { + + /* + * Make sure there are aggregates in the havingQual if so, + * the list must be longer after + * check_having_qual_for_aggs + */ + old_length = length(((Agg *) result_plan)->aggs); + + ((Agg *) result_plan)->aggs = nconc(((Agg *) result_plan)->aggs, + check_having_qual_for_aggs((Node *) lfirst(clause), + ((Agg *) result_plan)->plan.lefttree->targetlist, + ((List *) parse->groupClause))); + + /* + * Have a look at the length of the returned list. If + * there is no difference, no aggregates have been found + * and that means, that the Qual belongs to the where + * clause + */ + if (((new_length = length(((Agg *) result_plan)->aggs)) == old_length) || + (new_length == 0)) + { + elog(ERROR, "This could have been done in a where clause!!"); + return (Plan *) NIL; + } + } + PlannerVarParam = lnext(PlannerVarParam); + if (vpm != NULL) + pfree(vpm); + } + } - if (parse->rtable != NULL) - { - vpm = (List **) palloc(length(parse->rtable) * sizeof(List *)); - memset(vpm, 0, length(parse->rtable) * sizeof(List *)); - } - PlannerVarParam = lcons(vpm, PlannerVarParam); - - /* There is a subselect in the havingQual, so we have to process it - * using the same function as for a subselect in 'where' */ - if (parse->hasSubLinks) - { - parse->havingQual = SS_process_sublinks((Node *) parse->havingQual); - } - - /* convert the havingQual to conjunctive normal form (cnf) */ - parse->havingQual = (Node * ) cnfify((Expr *)(Node *) parse->havingQual,true); - - /* Calculate the opfids from the opnos (=select the correct functions for - * the used VAR datatypes) */ - parse->havingQual = (Node * ) fix_opids((List *) parse->havingQual); - - ((Agg *) result_plan)->plan.qual=(List *) parse->havingQual; - - /* Check every clause of the havingQual for aggregates used and append - * them to result_plan->aggs */ - foreach(clause, ((Agg *) result_plan)->plan.qual) - { - /* Make sure there are aggregates in the havingQual - * if so, the list must be longer after check_having_qual_for_aggs */ - old_length=length(((Agg *) result_plan)->aggs); - - ((Agg *) result_plan)->aggs = nconc(((Agg *) result_plan)->aggs, - check_having_qual_for_aggs((Node *) lfirst(clause), - ((Agg *) result_plan)->plan.lefttree->targetlist, - ((List *) parse->groupClause))); - - /* Have a look at the length of the returned list. If there is no - * difference, no aggregates have been found and that means, that - * the Qual belongs to the where clause */ - if (((new_length=length(((Agg *) result_plan)->aggs)) == old_length) || - (new_length == 0)) - { - elog(ERROR,"This could have been done in a where clause!!"); - return (Plan *)NIL; - } - } - PlannerVarParam = lnext(PlannerVarParam); - if (vpm != NULL) - pfree(vpm); - } - } - /* * For now, before we hand back the plan, check to see if there is a * user-specified sort that needs to be done. Eventually, this will @@ -530,6 +549,3 @@ pg_checkretval(Oid rettype, QueryTreeList *queryTreeList) /* success */ return; } - - - diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index 32f0b8225ff..6f134acddba 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.25 1998/09/01 03:23:40 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.26 1998/09/01 04:29:54 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -36,11 +36,9 @@ static void set_join_tlist_references(Join *join); static void set_tempscan_tlist_references(SeqScan *tempscan); static void set_temp_tlist_references(Temp *temp); -static List * -replace_clause_joinvar_refs(Expr *clause, +static List *replace_clause_joinvar_refs(Expr *clause, List *outer_tlist, List *inner_tlist); -static List * -replace_subclause_joinvar_refs(List *clauses, +static List *replace_subclause_joinvar_refs(List *clauses, List *outer_tlist, List *inner_tlist); static Var *replace_joinvar_refs(Var *var, List *outer_tlist, List *inner_tlist); static List *tlist_temp_references(Oid tempid, List *tlist); @@ -498,13 +496,13 @@ tlist_temp_references(Oid tempid, oattno = 0; temp = makeTargetEntry(xtl->resdom, - (Node *) makeVar(tempid, - xtl->resdom->resno, - xtl->resdom->restype, - xtl->resdom->restypmod, - 0, - tempid, - oattno)); + (Node *) makeVar(tempid, + xtl->resdom->resno, + xtl->resdom->restype, + xtl->resdom->restypmod, + 0, + tempid, + oattno)); t_list = lappend(t_list, temp); } @@ -901,190 +899,190 @@ del_agg_clause(Node *clause) /* check_having_qual_for_vars takes the the havingQual and the actual targetlist as arguments * and recursively scans the havingQual for attributes that are not included in the targetlist * yet. Attributes contained in the havingQual but not in the targetlist show up with queries - * like: - * SELECT sid + * like: + * SELECT sid * FROM part * GROUP BY sid - * HAVING MIN(pid) > 1; (pid is used but never selected for!!!). + * HAVING MIN(pid) > 1; (pid is used but never selected for!!!). * To be able to handle queries like that correctly we have to extend the actual targetlist - * (which will be the one used for the GROUP node later on) by these attributes. */ + * (which will be the one used for the GROUP node later on) by these attributes. */ List * check_having_qual_for_vars(Node *clause, List *targetlist_so_far) { - List *t; + List *t; + + + if (IsA(clause, Var)) + { + RelOptInfo tmp_rel; - if (IsA(clause, Var)) - { - RelOptInfo tmp_rel; - + tmp_rel.targetlist = targetlist_so_far; - tmp_rel.targetlist = targetlist_so_far; - - /* - * Ha! A Var node! - */ + /* + * Ha! A Var node! + */ + + /* Check if the VAR is already contained in the targetlist */ + if (tlist_member((Var *) clause, (List *) targetlist_so_far) == NULL) + add_tl_element(&tmp_rel, (Var *) clause); - /* Check if the VAR is already contained in the targetlist */ - if (tlist_member((Var *)clause, (List *)targetlist_so_far) == NULL) + return tmp_rel.targetlist; + } + + else if (is_funcclause(clause) || not_clause(clause) || + or_clause(clause) || and_clause(clause)) { - add_tl_element(&tmp_rel, (Var *)clause); - } - - return tmp_rel.targetlist; - } - - else if (is_funcclause(clause) || not_clause(clause) || - or_clause(clause) || and_clause(clause)) - { - - /* - * This is a function. Recursively call this routine for its - * arguments... - */ - foreach(t, ((Expr *) clause)->args) + + /* + * This is a function. Recursively call this routine for its + * arguments... + */ + foreach(t, ((Expr *) clause)->args) + targetlist_so_far = check_having_qual_for_vars(lfirst(t), targetlist_so_far); + return targetlist_so_far; + } + else if (IsA(clause, Aggreg)) { - targetlist_so_far = check_having_qual_for_vars(lfirst(t), targetlist_so_far); + targetlist_so_far = + check_having_qual_for_vars(((Aggreg *) clause)->target, targetlist_so_far); + return targetlist_so_far; } - return targetlist_so_far; - } - else if (IsA(clause, Aggreg)) - { - targetlist_so_far = - check_having_qual_for_vars(((Aggreg *) clause)->target, targetlist_so_far); - return targetlist_so_far; - } - else if (IsA(clause, ArrayRef)) - { - ArrayRef *aref = (ArrayRef *) clause; - - /* - * This is an arrayref. Recursively call this routine for its - * expression and its index expression... - */ - foreach(t, aref->refupperindexpr) + else if (IsA(clause, ArrayRef)) { - targetlist_so_far = check_having_qual_for_vars(lfirst(t), targetlist_so_far); + ArrayRef *aref = (ArrayRef *) clause; + + /* + * This is an arrayref. Recursively call this routine for its + * expression and its index expression... + */ + foreach(t, aref->refupperindexpr) + targetlist_so_far = check_having_qual_for_vars(lfirst(t), targetlist_so_far); + foreach(t, aref->reflowerindexpr) + targetlist_so_far = check_having_qual_for_vars(lfirst(t), targetlist_so_far); + targetlist_so_far = check_having_qual_for_vars(aref->refexpr, targetlist_so_far); + targetlist_so_far = check_having_qual_for_vars(aref->refassgnexpr, targetlist_so_far); + + return targetlist_so_far; + } + else if (is_opclause(clause)) + { + + /* + * This is an operator. Recursively call this routine for both its + * left and right operands + */ + Node *left = (Node *) get_leftop((Expr *) clause); + Node *right = (Node *) get_rightop((Expr *) clause); + + if (left != (Node *) NULL) + targetlist_so_far = check_having_qual_for_vars(left, targetlist_so_far); + if (right != (Node *) NULL) + targetlist_so_far = check_having_qual_for_vars(right, targetlist_so_far); + + return targetlist_so_far; } - foreach(t, aref->reflowerindexpr) + else if (IsA(clause, Param) ||IsA(clause, Const)) { - targetlist_so_far = check_having_qual_for_vars(lfirst(t), targetlist_so_far); + /* do nothing! */ + return targetlist_so_far; } - targetlist_so_far = check_having_qual_for_vars(aref->refexpr, targetlist_so_far); - targetlist_so_far = check_having_qual_for_vars(aref->refassgnexpr, targetlist_so_far); - - return targetlist_so_far; - } - else if (is_opclause(clause)) - { - - /* - * This is an operator. Recursively call this routine for both its - * left and right operands - */ - Node *left = (Node *) get_leftop((Expr *) clause); - Node *right = (Node *) get_rightop((Expr *) clause); - - if (left != (Node *) NULL) - targetlist_so_far = check_having_qual_for_vars(left, targetlist_so_far); - if (right != (Node *) NULL) - targetlist_so_far = check_having_qual_for_vars(right, targetlist_so_far); - - return targetlist_so_far; - } - else if (IsA(clause, Param) || IsA(clause, Const)) - { - /* do nothing! */ - return targetlist_so_far; - } - /* If we get to a sublink, then we only have to check the lefthand side of the expression - * to see if there are any additional VARs */ - else if (IsA(clause, SubLink)) - { - foreach(t,((List *)((SubLink *)clause)->lefthand)) + + /* + * If we get to a sublink, then we only have to check the lefthand + * side of the expression to see if there are any additional VARs + */ + else if (IsA(clause, SubLink)) { - targetlist_so_far = check_having_qual_for_vars(lfirst(t), targetlist_so_far); + foreach(t, ((List *) ((SubLink *) clause)->lefthand)) + targetlist_so_far = check_having_qual_for_vars(lfirst(t), targetlist_so_far); + return targetlist_so_far; + } + else + { + + /* + * Ooops! we can not handle that! + */ + elog(ERROR, "check_having_qual_for_vars: Can not handle this having_qual! %d\n", + nodeTag(clause)); + return NIL; } - return targetlist_so_far; - } - else - { - /* - * Ooops! we can not handle that! - */ - elog(ERROR, "check_having_qual_for_vars: Can not handle this having_qual! %d\n", - nodeTag(clause)); - return NIL; - } } -/* check_having_qual_for_aggs takes the havingQual, the targetlist and the groupClause +/* check_having_qual_for_aggs takes the havingQual, the targetlist and the groupClause * as arguments and scans the havingQual recursively for aggregates. If an aggregate is - * found it is attached to a list and returned by the function. (All the returned lists + * found it is attached to a list and returned by the function. (All the returned lists * are concenated to result_plan->aggs in planner.c:union_planner() */ List * check_having_qual_for_aggs(Node *clause, List *subplanTargetList, List *groupClause) { - List *t, *l1; + List *t, + *l1; List *agg_list = NIL; - int contained_in_group_clause = 0; - + int contained_in_group_clause = 0; + if (IsA(clause, Var)) { - TargetEntry *subplanVar; - - /* - * Ha! A Var node! - */ - subplanVar = match_varid((Var *) clause, subplanTargetList); - - /* - * Change the varno & varattno fields of the var node to point to the resdom->resno - * fields of the subplan (lefttree) - */ - ((Var *) clause)->varattno = subplanVar->resdom->resno; - - return NIL; + TargetEntry *subplanVar; + + /* + * Ha! A Var node! + */ + subplanVar = match_varid((Var *) clause, subplanTargetList); + + /* + * Change the varno & varattno fields of the var node to point to + * the resdom->resno fields of the subplan (lefttree) + */ + ((Var *) clause)->varattno = subplanVar->resdom->resno; + + return NIL; } - else if (is_funcclause(clause) || not_clause(clause) || - or_clause(clause) || and_clause(clause)) + else if (is_funcclause(clause) || not_clause(clause) || + or_clause(clause) || and_clause(clause)) { - int new_length=0, old_length=0; - + int new_length = 0, + old_length = 0; + /* * This is a function. Recursively call this routine for its * arguments... (i.e. for AND, OR, ... clauses!) */ foreach(t, ((Expr *) clause)->args) { - old_length=length((List *)agg_list); - - agg_list = nconc(agg_list, - check_having_qual_for_aggs(lfirst(t), subplanTargetList, - groupClause)); - - /* The arguments of OR or AND clauses are comparisons or relations - * and because we are in the havingQual there must be at least one operand - * using an aggregate function. If so, we will find it and the lenght of the - * agg_list will be increased after the above call to - * check_having_qual_for_aggs. If there are no aggregates used, the query - * could have been formulated using the 'where' clause */ - if(((new_length=length((List *)agg_list)) == old_length) || (new_length == 0)) - { - elog(ERROR,"This could have been done in a where clause!!"); - return NIL; - } + old_length = length((List *) agg_list); + + agg_list = nconc(agg_list, + check_having_qual_for_aggs(lfirst(t), subplanTargetList, + groupClause)); + + /* + * The arguments of OR or AND clauses are comparisons or + * relations and because we are in the havingQual there must + * be at least one operand using an aggregate function. If so, + * we will find it and the lenght of the agg_list will be + * increased after the above call to + * check_having_qual_for_aggs. If there are no aggregates + * used, the query could have been formulated using the + * 'where' clause + */ + if (((new_length = length((List *) agg_list)) == old_length) || (new_length == 0)) + { + elog(ERROR, "This could have been done in a where clause!!"); + return NIL; + } } return agg_list; } else if (IsA(clause, Aggreg)) { return lcons(clause, - check_having_qual_for_aggs(((Aggreg *) clause)->target, subplanTargetList, - groupClause)); + check_having_qual_for_aggs(((Aggreg *) clause)->target, subplanTargetList, + groupClause)); } else if (IsA(clause, ArrayRef)) { @@ -1097,21 +1095,21 @@ check_having_qual_for_aggs(Node *clause, List *subplanTargetList, List *groupCla foreach(t, aref->refupperindexpr) { agg_list = nconc(agg_list, - check_having_qual_for_aggs(lfirst(t), subplanTargetList, - groupClause)); + check_having_qual_for_aggs(lfirst(t), subplanTargetList, + groupClause)); } foreach(t, aref->reflowerindexpr) { agg_list = nconc(agg_list, - check_having_qual_for_aggs(lfirst(t), subplanTargetList, - groupClause)); + check_having_qual_for_aggs(lfirst(t), subplanTargetList, + groupClause)); } agg_list = nconc(agg_list, - check_having_qual_for_aggs(aref->refexpr, subplanTargetList, - groupClause)); + check_having_qual_for_aggs(aref->refexpr, subplanTargetList, + groupClause)); agg_list = nconc(agg_list, - check_having_qual_for_aggs(aref->refassgnexpr, subplanTargetList, - groupClause)); + check_having_qual_for_aggs(aref->refassgnexpr, subplanTargetList, + groupClause)); return agg_list; } @@ -1127,80 +1125,86 @@ check_having_qual_for_aggs(Node *clause, List *subplanTargetList, List *groupCla if (left != (Node *) NULL) agg_list = nconc(agg_list, - check_having_qual_for_aggs(left, subplanTargetList, - groupClause)); + check_having_qual_for_aggs(left, subplanTargetList, + groupClause)); if (right != (Node *) NULL) agg_list = nconc(agg_list, check_having_qual_for_aggs(right, subplanTargetList, - groupClause)); + groupClause)); return agg_list; } - else if (IsA(clause, Param) || IsA(clause, Const)) + else if (IsA(clause, Param) ||IsA(clause, Const)) { /* do nothing! */ return NIL; } - /* This is for Sublinks which show up as EXPR nodes. All the other EXPR nodes - * (funcclauses, and_clauses, or_clauses) were caught above */ + + /* + * This is for Sublinks which show up as EXPR nodes. All the other + * EXPR nodes (funcclauses, and_clauses, or_clauses) were caught above + */ else if (IsA(clause, Expr)) - { - /* Only the lefthand side of the sublink has to be checked for aggregates - * to be attached to result_plan->aggs (see planner.c:union_planner() ) - */ - foreach(t,((List *)((SubLink *)((SubPlan *) - ((Expr *)clause)->oper)->sublink)->lefthand)) - { - agg_list = - nconc(agg_list, - check_having_qual_for_aggs(lfirst(t), - subplanTargetList, groupClause)); - } - - - /* All arguments to the Sublink node are attributes from outside used within - * the sublink. Here we have to check that only attributes that is grouped for - * are used! */ - foreach(t,((Expr *)clause)->args) - { - contained_in_group_clause = 0; - - foreach(l1,groupClause) - { - if (tlist_member(lfirst(t),lcons(((GroupClause *)lfirst(l1))->entry,NIL)) != - NULL) - { - contained_in_group_clause=1; - } - } - - /* If the use of the attribute is allowed (i.e. it is in the groupClause) - * we have to adjust the varnos and varattnos */ - if (contained_in_group_clause) - { - agg_list = - nconc(agg_list, - check_having_qual_for_aggs(lfirst(t), - subplanTargetList, groupClause)); - } - else - { - elog(ERROR,"You must group by the attribute used from outside!"); - return NIL; - } - } - return agg_list; - } - else - { - /* - * Ooops! we can not handle that! - */ - elog(ERROR, "check_having_qual_for_aggs: Can not handle this having_qual! %d\n", - nodeTag(clause)); - return NIL; - } -} + { + /* + * Only the lefthand side of the sublink has to be checked for + * aggregates to be attached to result_plan->aggs (see + * planner.c:union_planner() ) + */ + foreach(t, ((List *) ((SubLink *) ((SubPlan *) + ((Expr *) clause)->oper)->sublink)->lefthand)) + { + agg_list = + nconc(agg_list, + check_having_qual_for_aggs(lfirst(t), + subplanTargetList, groupClause)); + } + /* + * All arguments to the Sublink node are attributes from outside + * used within the sublink. Here we have to check that only + * attributes that is grouped for are used! + */ + foreach(t, ((Expr *) clause)->args) + { + contained_in_group_clause = 0; + + foreach(l1, groupClause) + { + if (tlist_member(lfirst(t), lcons(((GroupClause *) lfirst(l1))->entry, NIL)) != + NULL) + contained_in_group_clause = 1; + } + + /* + * If the use of the attribute is allowed (i.e. it is in the + * groupClause) we have to adjust the varnos and varattnos + */ + if (contained_in_group_clause) + { + agg_list = + nconc(agg_list, + check_having_qual_for_aggs(lfirst(t), + subplanTargetList, groupClause)); + } + else + { + elog(ERROR, "You must group by the attribute used from outside!"); + return NIL; + } + } + return agg_list; + } + else + { + + /* + * Ooops! we can not handle that! + */ + elog(ERROR, "check_having_qual_for_aggs: Can not handle this having_qual! %d\n", + nodeTag(clause)); + return NIL; + } +} diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index 61d0df57afa..a1b4cd22cce 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -405,20 +405,23 @@ SS_process_sublinks(Node *expr) SS_process_sublinks((Node *) ((Expr *) expr)->args); else if (IsA(expr, SubLink))/* got it! */ { - /* Hack to make sure expr->oper->args points to the same VAR node - * as expr->lefthand does. Needed for subselects in the havingQual - * when used on views. - * Otherwise aggregate functions will fail later on (at execution - * time!) Reason: The rewite System makes several copies of the - * VAR nodes and in this case it should not do so :-( */ - if(((SubLink *) expr)->lefthand != NULL) + + /* + * Hack to make sure expr->oper->args points to the same VAR node + * as expr->lefthand does. Needed for subselects in the havingQual + * when used on views. Otherwise aggregate functions will fail + * later on (at execution time!) Reason: The rewite System makes + * several copies of the VAR nodes and in this case it should not + * do so :-( + */ + if (((SubLink *) expr)->lefthand != NULL) { - lfirst(((Expr *) lfirst(((SubLink *)expr)->oper))->args) = - lfirst(((SubLink *)expr)->lefthand); + lfirst(((Expr *) lfirst(((SubLink *) expr)->oper))->args) = + lfirst(((SubLink *) expr)->lefthand); } - expr = _make_subplan((SubLink *) expr); + expr = _make_subplan((SubLink *) expr); } - + return expr; } diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index 6fa90a13cf4..73ed555ff53 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.15 1998/09/01 03:23:44 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.16 1998/09/01 04:29:57 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,14 +34,11 @@ #include "optimizer/clauses.h" #include "optimizer/tlist.h" -static List * -expand_targetlist(List *tlist, Oid relid, int command_type, +static List *expand_targetlist(List *tlist, Oid relid, int command_type, Index result_relation); -static List * -replace_matching_resname(List *new_tlist, +static List *replace_matching_resname(List *new_tlist, List *old_tlist); -static List * -new_relation_targetlist(Oid relid, Index rt_index, +static List *new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type); @@ -295,13 +292,13 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type) false); temp3 = makeTargetEntry(makeResdom(attno, - atttype, - -1, - attname, - 0, - (Oid) 0, - 0), - (Node *) temp2); + atttype, + -1, + attname, + 0, + (Oid) 0, + 0), + (Node *) temp2); t_list = lappend(t_list, temp3); break; } @@ -316,13 +313,13 @@ new_relation_targetlist(Oid relid, Index rt_index, NodeTag node_type) 0, rt_index, attno); temp_list = makeTargetEntry(makeResdom(attno, - atttype, - get_atttypmod(relid, attno), - attname, - 0, - (Oid) 0, - 0), - (Node *) temp_var); + atttype, + get_atttypmod(relid, attno), + attname, + 0, + (Oid) 0, + 0), + (Node *) temp_var); t_list = lappend(t_list, temp_list); break; } diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c index f0242d7270b..06f270e118f 100644 --- a/src/backend/optimizer/prep/prepunion.c +++ b/src/backend/optimizer/prep/prepunion.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.26 1998/09/01 03:23:46 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.27 1998/09/01 04:29:59 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,21 +34,16 @@ #include "optimizer/planner.h" #include "optimizer/planmain.h" -static List * -plan_inherit_query(List *relids, Index rt_index, +static List *plan_inherit_query(List *relids, Index rt_index, RangeTblEntry *rt_entry, Query *parse, List **union_rtentriesPtr); -static RangeTblEntry * -new_rangetable_entry(Oid new_relid, +static RangeTblEntry *new_rangetable_entry(Oid new_relid, RangeTblEntry *old_entry); -static Query * -subst_rangetable(Query *root, Index index, +static Query *subst_rangetable(Query *root, Index index, RangeTblEntry *new_entry); -static void -fix_parsetree_attnums(Index rt_index, Oid old_relid, +static void fix_parsetree_attnums(Index rt_index, Oid old_relid, Oid new_relid, Query *parsetree); -static Append * -make_append(List *appendplans, List *unionrtables, Index rt_index, +static Append *make_append(List *appendplans, List *unionrtables, Index rt_index, List *inheritrtable, List *tlist); @@ -89,7 +84,7 @@ plan_union_queries(Query *parse) * * So the above query becomes: * - * Append Node + * Append Node * { * Sort and Unique * { @@ -281,7 +276,7 @@ plan_inherit_query(List *relids, new_root->sortClause = NULL; new_root->groupClause = NULL; new_root->havingQual = NULL; - + if (new_root->hasAggs) { new_root->hasAggs = false; @@ -502,14 +497,14 @@ make_append(List *appendplans, { Append *node = makeNode(Append); List *subnode; - + node->appendplans = appendplans; node->unionrtables = unionrtables; node->inheritrelid = rt_index; node->inheritrtable = inheritrtable; node->plan.cost = 0.0; foreach(subnode, appendplans) - node->plan.cost += ((Plan *)lfirst(subnode))->cost; + node->plan.cost += ((Plan *) lfirst(subnode))->cost; node->plan.state = (EState *) NULL; node->plan.targetlist = tlist; node->plan.qual = NIL; diff --git a/src/backend/optimizer/util/clauseinfo.c b/src/backend/optimizer/util/clauseinfo.c index 0385edaae9a..207074bb1a0 100644 --- a/src/backend/optimizer/util/clauseinfo.c +++ b/src/backend/optimizer/util/clauseinfo.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/clauseinfo.c,v 1.8 1998/09/01 03:23:47 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/clauseinfo.c,v 1.9 1998/09/01 04:30:00 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -27,7 +27,7 @@ * */ bool -valid_or_clause(ClauseInfo *clauseinfo) +valid_or_clause(ClauseInfo * clauseinfo) { if (clauseinfo != NULL && !single_node((Node *) clauseinfo->clause) && @@ -49,7 +49,7 @@ get_actual_clauses(List *clauseinfo_list) { List *temp = NIL; List *result = NIL; - ClauseInfo *clause = (ClauseInfo *) NULL; + ClauseInfo *clause = (ClauseInfo *) NULL; foreach(temp, clauseinfo_list) { @@ -93,7 +93,7 @@ get_relattvals(List *clauseinfo_list, List *result1 = NIL; List *result2 = NIL; List *result3 = NIL; - ClauseInfo *temp = (ClauseInfo *) NULL; + ClauseInfo *temp = (ClauseInfo *) NULL; List *i = NIL; foreach(i, clauseinfo_list) @@ -144,7 +144,7 @@ get_joinvars(Oid relid, foreach(temp, clauseinfo_list) { - ClauseInfo *clauseinfo = lfirst(temp); + ClauseInfo *clauseinfo = lfirst(temp); Expr *clause = clauseinfo->clause; if (IsA(get_leftop(clause), Var) && @@ -176,7 +176,7 @@ get_joinvars(Oid relid, List * get_opnos(List *clauseinfo_list) { - ClauseInfo *temp = (ClauseInfo *) NULL; + ClauseInfo *temp = (ClauseInfo *) NULL; List *result = NIL; List *i = NIL; diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index 0ec0f74ca17..19bd3ce98e1 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.23 1998/09/01 03:23:49 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.24 1998/09/01 04:30:02 momjian Exp $ * * HISTORY * AUTHOR DATE MAJOR EVENT @@ -199,8 +199,8 @@ bool or_clause(Node *clause) { return clause != NULL && - nodeTag(clause) == T_Expr && - ((Expr *) clause)->opType == OR_EXPR; + nodeTag(clause) == T_Expr && + ((Expr *) clause)->opType == OR_EXPR; } /* @@ -460,7 +460,7 @@ is_joinable(Node *clause) * One side of the clause (i.e. left or right operands) must either be * a var node ... */ - if (IsA(leftop, Var) || IsA(rightop, Var)) + if (IsA(leftop, Var) ||IsA(rightop, Var)) return true; /* diff --git a/src/backend/optimizer/util/indexnode.c b/src/backend/optimizer/util/indexnode.c index a48c817e1f5..d83b353cc53 100644 --- a/src/backend/optimizer/util/indexnode.c +++ b/src/backend/optimizer/util/indexnode.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.9 1998/09/01 03:23:50 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/indexnode.c,v 1.10 1998/09/01 04:30:04 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -33,7 +33,7 @@ static List *find_secondary_index(Query *root, Oid relid); * */ List * -find_relation_indices(Query *root, RelOptInfo *rel) +find_relation_indices(Query *root, RelOptInfo * rel) { if (rel->indexed) return find_secondary_index(root, lfirsti(rel->relids)); @@ -61,7 +61,7 @@ find_secondary_index(Query *root, Oid relid) while (index_info(root, first, relid, &indexinfo)) { - RelOptInfo *indexnode = makeNode(RelOptInfo); + RelOptInfo *indexnode = makeNode(RelOptInfo); indexnode->relids = lconsi(indexinfo.relid, NIL); indexnode->relam = indexinfo.relam; diff --git a/src/backend/optimizer/util/joininfo.c b/src/backend/optimizer/util/joininfo.c index 9e45905bc81..50e3065f825 100644 --- a/src/backend/optimizer/util/joininfo.c +++ b/src/backend/optimizer/util/joininfo.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.11 1998/09/01 03:23:52 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/joininfo.c,v 1.12 1998/09/01 04:30:05 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -35,7 +35,7 @@ * exists. * */ -JoinInfo * +JoinInfo * joininfo_member(List *join_relids, List *joininfo_list) { List *i = NIL; @@ -61,10 +61,10 @@ joininfo_member(List *join_relids, List *joininfo_list) * Returns a joininfo node. * */ -JoinInfo * -find_joininfo_node(RelOptInfo *this_rel, List *join_relids) +JoinInfo * +find_joininfo_node(RelOptInfo * this_rel, List *join_relids) { - JoinInfo *joininfo = joininfo_member(join_relids, + JoinInfo *joininfo = joininfo_member(join_relids, this_rel->joininfo); if (joininfo == NULL) diff --git a/src/backend/optimizer/util/keys.c b/src/backend/optimizer/util/keys.c index 9ecf7377aba..3e2372339d3 100644 --- a/src/backend/optimizer/util/keys.c +++ b/src/backend/optimizer/util/keys.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/keys.c,v 1.8 1998/09/01 03:23:53 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/keys.c,v 1.9 1998/09/01 04:30:07 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -54,7 +54,7 @@ static bool equal_indexkey_var(int index_key, Var *var); * */ bool -match_indexkey_operand(int indexkey, Var *operand, RelOptInfo *rel) +match_indexkey_operand(int indexkey, Var *operand, RelOptInfo * rel) { if (IsA(operand, Var) && (lfirsti(rel->relids) == operand->varno) && diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index bdd4e4509aa..598400fa49a 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.11 1998/09/01 03:23:55 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/pathnode.c,v 1.12 1998/09/01 04:30:08 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -62,7 +62,7 @@ path_is_cheaper(Path *path1, Path *path2) * */ Path * -set_cheapest(RelOptInfo *parent_rel, List *pathlist) +set_cheapest(RelOptInfo * parent_rel, List *pathlist) { List *p; Path *cheapest_so_far; @@ -99,7 +99,7 @@ set_cheapest(RelOptInfo *parent_rel, List *pathlist) * */ List * -add_pathlist(RelOptInfo *parent_rel, List *unique_paths, List *new_paths) +add_pathlist(RelOptInfo * parent_rel, List *unique_paths, List *new_paths) { List *x; Path *new_path; @@ -200,7 +200,7 @@ better_path(Path *new_path, List *unique_paths, bool *noOther) * */ Path * -create_seqscan_path(RelOptInfo *rel) +create_seqscan_path(RelOptInfo * rel) { int relid = 0; @@ -251,8 +251,8 @@ create_seqscan_path(RelOptInfo *rel) */ IndexPath * create_index_path(Query *root, - RelOptInfo *rel, - RelOptInfo *index, + RelOptInfo * rel, + RelOptInfo * index, List *restriction_clauses, bool is_join_scan) { @@ -406,8 +406,8 @@ create_index_path(Query *root, * */ JoinPath * -create_nestloop_path(RelOptInfo *joinrel, - RelOptInfo *outer_rel, +create_nestloop_path(RelOptInfo * joinrel, + RelOptInfo * outer_rel, Path *outer_path, Path *inner_path, List *keys) @@ -481,7 +481,7 @@ create_nestloop_path(RelOptInfo *joinrel, * */ MergePath * -create_mergejoin_path(RelOptInfo *joinrel, +create_mergejoin_path(RelOptInfo * joinrel, int outersize, int innersize, int outerwidth, @@ -547,7 +547,7 @@ create_mergejoin_path(RelOptInfo *joinrel, * */ HashPath * -create_hashjoin_path(RelOptInfo *joinrel, +create_hashjoin_path(RelOptInfo * joinrel, int outersize, int innersize, int outerwidth, diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index b04efb5a362..786947e809a 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.20 1998/09/01 03:23:56 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.21 1998/09/01 04:30:09 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -40,10 +40,9 @@ #endif -static void -IndexSelectivity(Oid indexrelid, Oid indrelid, int32 nIndexKeys, - Oid *AccessMethodOperatorClasses, Oid *operatorObjectIds, - int32 *varAttributeNumbers, char **constValues, int32 *constFlags, +static void IndexSelectivity(Oid indexrelid, Oid indrelid, int32 nIndexKeys, + Oid *AccessMethodOperatorClasses, Oid *operatorObjectIds, + int32 *varAttributeNumbers, char **constValues, int32 *constFlags, float *idxPages, float *idxSelec); @@ -65,7 +64,7 @@ relation_info(Query *root, Index relid, relationObjectId = getrelid(relid, root->rtable); relationTuple = SearchSysCacheTuple(RELOID, - ObjectIdGetDatum(relationObjectId), + ObjectIdGetDatum(relationObjectId), 0, 0, 0); if (HeapTupleIsValid(relationTuple)) { @@ -195,7 +194,7 @@ index_info(Query *root, bool first, int relid, IdxInfoRetval *info) #ifdef notdef /* XXX should iterate through strategies -- but how? use #1 for now */ amstrategy = indexRelation->rd_am->amstrategies; -#endif /* notdef */ +#endif /* notdef */ amstrategy = 1; relam = indexRelation->rd_rel->relam; info->relam = relam; diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index 869b4ff6bd4..52bcd059dba 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.8 1998/09/01 03:23:58 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/relnode.c,v 1.9 1998/09/01 04:30:11 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -31,7 +31,7 @@ RelOptInfo * get_base_rel(Query *root, int relid) { List *relids; - RelOptInfo *rel; + RelOptInfo *rel; relids = lconsi(relid, NIL); rel = rel_member(relids, root->base_rel_list); @@ -65,6 +65,7 @@ get_base_rel(Query *root, int relid) */ if (relid < 0) { + /* * If the relation is a materialized relation, assume * constants for sizes. diff --git a/src/backend/optimizer/util/tlist.c b/src/backend/optimizer/util/tlist.c index 8aee7a16456..8400e967252 100644 --- a/src/backend/optimizer/util/tlist.c +++ b/src/backend/optimizer/util/tlist.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.17 1998/09/01 03:23:59 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/tlist.c,v 1.18 1998/09/01 04:30:12 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -93,7 +93,7 @@ matching_tlvar(Var *var, List *targetlist) * CREATES: new var-node iff no matching var-node exists in targetlist */ void -add_tl_element(RelOptInfo *rel, Var *var) +add_tl_element(RelOptInfo * rel, Var *var) { Expr *oldvar = (Expr *) NULL; @@ -134,14 +134,14 @@ TargetEntry * create_tl_element(Var *var, int resdomno) { - return makeTargetEntry(makeResdom(resdomno, - var->vartype, - var->vartypmod, - NULL, - (Index) 0, - (Oid) 0, - 0), - (Node *) var); + return makeTargetEntry(makeResdom(resdomno, + var->vartype, + var->vartypmod, + NULL, + (Index) 0, + (Oid) 0, + 0), + (Node *) var); } /* @@ -348,7 +348,7 @@ copy_vars(List *target, List *source) dest != NIL; src = lnext(src), dest = lnext(dest)) { TargetEntry *temp = makeTargetEntry(((TargetEntry *) lfirst(dest))->resdom, - (Node *) get_expr(lfirst(src))); + (Node *) get_expr(lfirst(src))); result = lappend(result, temp); } @@ -432,8 +432,8 @@ flatten_tlist_vars(List *full_tlist, List *flat_tlist) result = lappend(result, makeTargetEntry(tle->resdom, - flatten_tlistentry((Node *) get_expr(tle), - flat_tlist))); + flatten_tlistentry((Node *) get_expr(tle), + flat_tlist))); } return result; |