From 6e2edaf4b8efa1590555dad1f45fe1df4a19ca9a Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 5 Feb 1999 19:59:31 +0000 Subject: Optimizer cleanup. --- src/backend/nodes/copyfuncs.c | 4 +- src/backend/nodes/outfuncs.c | 4 +- src/backend/nodes/readfuncs.c | 6 +- src/backend/optimizer/path/indxpath.c | 18 +-- src/backend/optimizer/path/prune.c | 6 +- src/backend/optimizer/plan/createplan.c | 4 +- src/backend/optimizer/util/Makefile | 4 +- src/backend/optimizer/util/clauseinfo.c | 190 ------------------------------ src/backend/optimizer/util/ordering.c | 4 +- src/backend/optimizer/util/restrictinfo.c | 190 ++++++++++++++++++++++++++++++ src/include/nodes/relation.h | 4 +- 11 files changed, 217 insertions(+), 217 deletions(-) delete mode 100644 src/backend/optimizer/util/clauseinfo.c create mode 100644 src/backend/optimizer/util/restrictinfo.c (limited to 'src') diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 7b234224e1c..deecc3aa33d 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.61 1999/02/04 03:19:06 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.62 1999/02/05 19:59:25 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1343,7 +1343,7 @@ _copyRestrictInfo(RestrictInfo * from) Node_Copy(from, newnode, indexids); Node_Copy(from, newnode, mergejoinorder); newnode->hashjoinoperator = from->hashjoinoperator; - newnode->cinfojoinid = listCopy(from->cinfojoinid); + newnode->restrictinfojoinid = listCopy(from->restrictinfojoinid); return newnode; } diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 8c0d49a7c32..fd2bb20f554 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -5,7 +5,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: outfuncs.c,v 1.64 1999/02/04 01:46:54 momjian Exp $ + * $Id: outfuncs.c,v 1.65 1999/02/05 19:59:25 momjian Exp $ * * NOTES * Every (plan) node in POSTGRES has an associated "out" routine which @@ -1107,7 +1107,7 @@ _outMergeOrder(StringInfo str, MergeOrder *node) static void _outRestrictInfo(StringInfo str, RestrictInfo * node) { - appendStringInfo(str, " CINFO :clause "); + appendStringInfo(str, " RESTRICTINFO :clause "); _outNode(str, node->clause); appendStringInfo(str, diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index f3ac661b0a4..43c71c6a81d 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.48 1999/02/04 03:19:06 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.49 1999/02/05 19:59:25 momjian Exp $ * * NOTES * Most of the read functions for plan nodes are tested. (In fact, they @@ -2087,13 +2087,13 @@ parsePlanString(void) return_value = _readJoinKey(); else if (!strncmp(token, "MERGEORDER", length)) return_value = _readMergeOrder(); - else if (!strncmp(token, "CLAUSEINFO", length)) + else if (!strncmp(token, "RETRICTINFO", length)) return_value = _readRestrictInfo(); else if (!strncmp(token, "JOINMETHOD", length)) return_value = _readJoinMethod(); else if (!strncmp(token, "JOININFO", length)) return_value = _readJoinInfo(); - else if (!strncmp(token, "HINFO", length)) + else if (!strncmp(token, "HASHINFO", length)) return_value = _readHashInfo(); else if (!strncmp(token, "ITER", length)) return_value = _readIter(); diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 42cbade63ad..ae937cc9763 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.37 1999/02/03 21:16:26 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.38 1999/02/05 19:59:26 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -56,7 +56,7 @@ static List *group_clauses_by_indexkey(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 RestrictInfo *match_clause_to_indexkey(RelOptInfo * rel, RelOptInfo * index, int indexkey, - int xclass, RestrictInfo * clauseInfo, bool join); + int xclass, RestrictInfo * restrictInfo, bool join); static bool pred_test(List *predicate_list, List *restrictinfo_list, List *joininfo_list); static bool one_pred_test(Expr *predicate, List *restrictinfo_list); @@ -571,14 +571,14 @@ group_clauses_by_ikey_for_joins(RelOptInfo * rel, * */ static RestrictInfo * -match_clause_to_indexkey(RelOptInfo * rel, - RelOptInfo * index, +match_clause_to_indexkey(RelOptInfo *rel, + RelOptInfo *index, int indexkey, int xclass, - RestrictInfo * clauseInfo, + RestrictInfo *restrictInfo, bool join) { - Expr *clause = clauseInfo->clause; + Expr *clause = restrictInfo->clause; Var *leftop, *rightop; Oid join_op = InvalidOid; @@ -761,7 +761,7 @@ match_clause_to_indexkey(RelOptInfo * rel, } if (isIndexable) - return clauseInfo; + return restrictInfo; return NULL; } @@ -1208,7 +1208,7 @@ indexable_joinclauses(RelOptInfo * rel, RelOptInfo * index, { List *clauses = lfirst(clausegroups); - ((RestrictInfo *) lfirst(clauses))->cinfojoinid = joininfo->otherrels; + ((RestrictInfo *) lfirst(clauses))->restrictinfojoinid = joininfo->otherrels; } cg_list = nconc(cg_list, clausegroups); } @@ -1298,7 +1298,7 @@ index_innerjoin(Query *root, RelOptInfo * rel, List *clausegroup_list, pathnode->indexkeys = index->indexkeys; pathnode->indexqual = clausegroup; - pathnode->path.joinid = ((RestrictInfo *) lfirst(clausegroup))->cinfojoinid; + pathnode->path.joinid = ((RestrictInfo *) lfirst(clausegroup))->restrictinfojoinid; pathnode->path.path_cost = cost_index((Oid) lfirsti(index->relids), (int) temp_pages, diff --git a/src/backend/optimizer/path/prune.c b/src/backend/optimizer/path/prune.c index 4a185c13d50..f02bfeaab5b 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.21 1999/02/05 03:43:05 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/Attic/prune.c,v 1.22 1999/02/05 19:59:26 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -64,9 +64,9 @@ prune_joinrel(RelOptInfo *rel, List *other_rels) List *r1 = NIL; List *result = NIL; - foreach(r1, other_rels) + foreach(i, other_rels) { - RelOptInfo *other_rel = (RelOptInfo *) lfirst(r1); + RelOptInfo *other_rel = (RelOptInfo *) lfirst(i); if (same(rel->relids, other_rel->relids)) /* diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 86a143199c4..e2bdb295dac 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.36 1999/02/03 21:16:30 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.37 1999/02/05 19:59:27 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -321,7 +321,7 @@ create_indexscan_node(IndexPath *best_path, /* * Extract the(first if conjunct, only if disjunct) clause from the - * clauseinfo list. + * restrictinfo list. */ Expr *index_clause = (Expr *) NULL; List *indxqual = NIL; diff --git a/src/backend/optimizer/util/Makefile b/src/backend/optimizer/util/Makefile index f930c721b7b..f28457497f0 100644 --- a/src/backend/optimizer/util/Makefile +++ b/src/backend/optimizer/util/Makefile @@ -4,7 +4,7 @@ # Makefile for optimizer/util # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/backend/optimizer/util/Makefile,v 1.7 1998/07/20 20:01:48 momjian Exp $ +# $Header: /cvsroot/pgsql/src/backend/optimizer/util/Makefile,v 1.8 1999/02/05 19:59:28 momjian Exp $ # #------------------------------------------------------------------------- @@ -13,7 +13,7 @@ include ../../../Makefile.global CFLAGS += -I../.. -OBJS = clauseinfo.o clauses.o indexnode.o plancat.o \ +OBJS = restrictinfo.o clauses.o indexnode.o plancat.o \ joininfo.o keys.o ordering.o pathnode.o relnode.o tlist.o var.o # not ready yet: predmig.o xfunc.o diff --git a/src/backend/optimizer/util/clauseinfo.c b/src/backend/optimizer/util/clauseinfo.c deleted file mode 100644 index 4df034536c0..00000000000 --- a/src/backend/optimizer/util/clauseinfo.c +++ /dev/null @@ -1,190 +0,0 @@ -/*------------------------------------------------------------------------- - * - * restrictinfo.c-- - * RestrictInfo node manipulation routines. - * - * Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/clauseinfo.c,v 1.11 1999/02/03 21:16:50 momjian Exp $ - * - *------------------------------------------------------------------------- - */ -#include "postgres.h" - -#include "nodes/relation.h" -#include "nodes/nodeFuncs.h" - -#include "optimizer/internal.h" -#include "optimizer/clauses.h" -#include "optimizer/restrictinfo.h" - -/* - * valid-or-clause-- - * - * Returns t iff the restrictinfo node contains a 'normal' 'or' clause. - * - */ -bool -valid_or_clause(RestrictInfo * restrictinfo) -{ - if (restrictinfo != NULL && - !single_node((Node *) restrictinfo->clause) && - !restrictinfo->notclause && - or_clause((Node *) restrictinfo->clause)) - return true; - else - return false; -} - -/* - * get-actual-clauses-- - * - * Returns a list containing the clauses from 'restrictinfo-list'. - * - */ -List * -get_actual_clauses(List *restrictinfo_list) -{ - List *temp = NIL; - List *result = NIL; - RestrictInfo *clause = (RestrictInfo *) NULL; - - foreach(temp, restrictinfo_list) - { - clause = (RestrictInfo *) lfirst(temp); - result = lappend(result, clause->clause); - } - return result; -} - -/* - * XXX NOTE: - * The following routines must return their contents in the same order - * (e.g., the first clause's info should be first, and so on) or else - * get_index_sel() won't work. - * - */ - -/* - * get_relattvals-- - * For each member of a list of restrictinfo nodes to be used with an - * index, create a vectori-long specifying: - * the attnos, - * the values of the clause constants, and - * flags indicating the type and location of the constant within - * each clause. - * Each clause is of the form (op var some_type_of_constant), thus the - * flag indicating whether the constant is on the left or right should - * always be *SELEC-CONSTANT-RIGHT*. - * - * 'restrictinfo-list' is a list of restrictinfo nodes - * - * Returns a list of vectori-longs. - * - */ -void -get_relattvals(List *restrictinfo_list, - List **attnos, - List **values, - List **flags) -{ - List *result1 = NIL; - List *result2 = NIL; - List *result3 = NIL; - RestrictInfo *temp = (RestrictInfo *) NULL; - List *i = NIL; - - foreach(i, restrictinfo_list) - { - int dummy; - AttrNumber attno; - Datum constval; - int flag; - - temp = (RestrictInfo *) lfirst(i); - get_relattval((Node *) temp->clause, &dummy, &attno, &constval, &flag); - result1 = lappendi(result1, (int) attno); - result2 = lappendi(result2, constval); - result3 = lappendi(result3, flag); - } - - *attnos = result1; - *values = result2; - *flags = result3; - return; -} - -/* - * get_joinvars -- - * Given a list of join restrictinfo nodes to be used with the index - * of an inner join relation, return three lists consisting of: - * the attributes corresponding to the inner join relation - * the value of the inner var clause (always "") - * whether the attribute appears on the left or right side of - * the operator. - * - * 'relid' is the inner join relation - * 'restrictinfo-list' is a list of qualification clauses to be used with - * 'rel' - * - */ -void -get_joinvars(Oid relid, - List *restrictinfo_list, - List **attnos, - List **values, - List **flags) -{ - List *result1 = NIL; - List *result2 = NIL; - List *result3 = NIL; - List *temp; - - foreach(temp, restrictinfo_list) - { - RestrictInfo *restrictinfo = lfirst(temp); - Expr *clause = restrictinfo->clause; - - if (IsA(get_leftop(clause), Var) && - (relid == (get_leftop(clause))->varno)) - { - result1 = lappendi(result1, (int4) (get_leftop(clause))->varattno); - result2 = lappend(result2, ""); - result3 = lappendi(result3, _SELEC_CONSTANT_RIGHT_); - } - else - { - result1 = lappendi(result1, (int4) (get_rightop(clause))->varattno); - result2 = lappend(result2, ""); - result3 = lappendi(result3, _SELEC_CONSTANT_LEFT_); - } - } - *attnos = result1; - *values = result2; - *flags = result3; - return; -} - -/* - * get_opnos-- - * Create and return a list containing the clause operators of each member - * of a list of restrictinfo nodes to be used with an index. - * - */ -List * -get_opnos(List *restrictinfo_list) -{ - RestrictInfo *temp = (RestrictInfo *) NULL; - List *result = NIL; - List *i = NIL; - - foreach(i, restrictinfo_list) - { - temp = (RestrictInfo *) lfirst(i); - result = lappendi(result, - (((Oper *) temp->clause->oper)->opno)); - } - return result; -} diff --git a/src/backend/optimizer/util/ordering.c b/src/backend/optimizer/util/ordering.c index d13e014b51a..15d389e5f6b 100644 --- a/src/backend/optimizer/util/ordering.c +++ b/src/backend/optimizer/util/ordering.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/ordering.c,v 1.9 1999/02/03 21:16:51 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/Attic/ordering.c,v 1.10 1999/02/05 19:59:30 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -44,7 +44,7 @@ equal_path_path_ordering(PathOrder *path_ordering1, path_ordering2->ordtype == SORTOP_ORDER) { return (equal_sortops_order(path_ordering1->ord.sortop, - path_ordering2->ord.sortop)); + path_ordering2->ord.sortop)); } else if (path_ordering1->ordtype == MERGE_ORDER && path_ordering2->ordtype == SORTOP_ORDER) diff --git a/src/backend/optimizer/util/restrictinfo.c b/src/backend/optimizer/util/restrictinfo.c new file mode 100644 index 00000000000..22ffe665e2e --- /dev/null +++ b/src/backend/optimizer/util/restrictinfo.c @@ -0,0 +1,190 @@ +/*------------------------------------------------------------------------- + * + * restrictinfo.c-- + * RestrictInfo node manipulation routines. + * + * Copyright (c) 1994, Regents of the University of California + * + * + * IDENTIFICATION + * $Header: /cvsroot/pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.1 1999/02/05 19:59:31 momjian Exp $ + * + *------------------------------------------------------------------------- + */ +#include "postgres.h" + +#include "nodes/relation.h" +#include "nodes/nodeFuncs.h" + +#include "optimizer/internal.h" +#include "optimizer/clauses.h" +#include "optimizer/restrictinfo.h" + +/* + * valid-or-clause-- + * + * Returns t iff the restrictinfo node contains a 'normal' 'or' clause. + * + */ +bool +valid_or_clause(RestrictInfo * restrictinfo) +{ + if (restrictinfo != NULL && + !single_node((Node *) restrictinfo->clause) && + !restrictinfo->notclause && + or_clause((Node *) restrictinfo->clause)) + return true; + else + return false; +} + +/* + * get-actual-clauses-- + * + * Returns a list containing the clauses from 'restrictinfo-list'. + * + */ +List * +get_actual_clauses(List *restrictinfo_list) +{ + List *temp = NIL; + List *result = NIL; + RestrictInfo *clause = (RestrictInfo *) NULL; + + foreach(temp, restrictinfo_list) + { + clause = (RestrictInfo *) lfirst(temp); + result = lappend(result, clause->clause); + } + return result; +} + +/* + * XXX NOTE: + * The following routines must return their contents in the same order + * (e.g., the first clause's info should be first, and so on) or else + * get_index_sel() won't work. + * + */ + +/* + * get_relattvals-- + * For each member of a list of restrictinfo nodes to be used with an + * index, create a vectori-long specifying: + * the attnos, + * the values of the clause constants, and + * flags indicating the type and location of the constant within + * each clause. + * Each clause is of the form (op var some_type_of_constant), thus the + * flag indicating whether the constant is on the left or right should + * always be *SELEC-CONSTANT-RIGHT*. + * + * 'restrictinfo-list' is a list of restrictinfo nodes + * + * Returns a list of vectori-longs. + * + */ +void +get_relattvals(List *restrictinfo_list, + List **attnos, + List **values, + List **flags) +{ + List *result1 = NIL; + List *result2 = NIL; + List *result3 = NIL; + RestrictInfo *temp = (RestrictInfo *) NULL; + List *i = NIL; + + foreach(i, restrictinfo_list) + { + int dummy; + AttrNumber attno; + Datum constval; + int flag; + + temp = (RestrictInfo *) lfirst(i); + get_relattval((Node *) temp->clause, &dummy, &attno, &constval, &flag); + result1 = lappendi(result1, (int) attno); + result2 = lappendi(result2, constval); + result3 = lappendi(result3, flag); + } + + *attnos = result1; + *values = result2; + *flags = result3; + return; +} + +/* + * get_joinvars -- + * Given a list of join restrictinfo nodes to be used with the index + * of an inner join relation, return three lists consisting of: + * the attributes corresponding to the inner join relation + * the value of the inner var clause (always "") + * whether the attribute appears on the left or right side of + * the operator. + * + * 'relid' is the inner join relation + * 'restrictinfo-list' is a list of qualification clauses to be used with + * 'rel' + * + */ +void +get_joinvars(Oid relid, + List *restrictinfo_list, + List **attnos, + List **values, + List **flags) +{ + List *result1 = NIL; + List *result2 = NIL; + List *result3 = NIL; + List *temp; + + foreach(temp, restrictinfo_list) + { + RestrictInfo *restrictinfo = lfirst(temp); + Expr *clause = restrictinfo->clause; + + if (IsA(get_leftop(clause), Var) && + (relid == (get_leftop(clause))->varno)) + { + result1 = lappendi(result1, (int4) (get_leftop(clause))->varattno); + result2 = lappend(result2, ""); + result3 = lappendi(result3, _SELEC_CONSTANT_RIGHT_); + } + else + { + result1 = lappendi(result1, (int4) (get_rightop(clause))->varattno); + result2 = lappend(result2, ""); + result3 = lappendi(result3, _SELEC_CONSTANT_LEFT_); + } + } + *attnos = result1; + *values = result2; + *flags = result3; + return; +} + +/* + * get_opnos-- + * Create and return a list containing the clause operators of each member + * of a list of restrictinfo nodes to be used with an index. + * + */ +List * +get_opnos(List *restrictinfo_list) +{ + RestrictInfo *temp = (RestrictInfo *) NULL; + List *result = NIL; + List *i = NIL; + + foreach(i, restrictinfo_list) + { + temp = (RestrictInfo *) lfirst(i); + result = lappendi(result, + (((Oper *) temp->clause->oper)->opno)); + } + return result; +} diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 45bb715e671..51b30d4c4e3 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -6,7 +6,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: relation.h,v 1.14 1999/02/04 03:19:10 momjian Exp $ + * $Id: relation.h,v 1.15 1999/02/05 19:59:31 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -219,7 +219,7 @@ typedef struct RestrictInfo /* hashjoin only */ Oid hashjoinoperator; - Relid cinfojoinid; + Relid restrictinfojoinid; } RestrictInfo; typedef struct JoinMethod -- cgit v1.2.3