diff options
Diffstat (limited to 'src/backend/optimizer/plan')
-rw-r--r-- | src/backend/optimizer/plan/createplan.c | 67 | ||||
-rw-r--r-- | src/backend/optimizer/plan/initsplan.c | 9 | ||||
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 51 | ||||
-rw-r--r-- | src/backend/optimizer/plan/setrefs.c | 18 | ||||
-rw-r--r-- | src/backend/optimizer/plan/subselect.c | 51 |
5 files changed, 107 insertions, 89 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index beb903f785d..11d37ac0b54 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.173 2004/08/29 04:12:33 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.174 2004/08/29 05:06:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -45,11 +45,11 @@ static Result *create_result_plan(Query *root, ResultPath *best_path); static Material *create_material_plan(Query *root, MaterialPath *best_path); static Plan *create_unique_plan(Query *root, UniquePath *best_path); static SeqScan *create_seqscan_plan(Query *root, Path *best_path, - List *tlist, List *scan_clauses); + List *tlist, List *scan_clauses); static IndexScan *create_indexscan_plan(Query *root, IndexPath *best_path, List *tlist, List *scan_clauses); static TidScan *create_tidscan_plan(Query *root, TidPath *best_path, - List *tlist, List *scan_clauses); + List *tlist, List *scan_clauses); static SubqueryScan *create_subqueryscan_plan(Query *root, Path *best_path, List *tlist, List *scan_clauses); static FunctionScan *create_functionscan_plan(Query *root, Path *best_path, @@ -712,7 +712,7 @@ create_indexscan_plan(Query *root, * If this is a innerjoin scan, the indexclauses will contain join * clauses that are not present in scan_clauses (since the passed-in * value is just the rel's baserestrictinfo list). We must add these - * clauses to scan_clauses to ensure they get checked. In most cases + * clauses to scan_clauses to ensure they get checked. In most cases * we will remove the join clauses again below, but if a join clause * contains a special operator, we need to make sure it gets into the * scan_clauses. @@ -721,12 +721,12 @@ create_indexscan_plan(Query *root, { /* * We don't currently support OR indexscans in joins, so we only - * need to worry about the plain AND case. Also, pointer comparison - * should be enough to determine RestrictInfo matches. + * need to worry about the plain AND case. Also, pointer + * comparison should be enough to determine RestrictInfo matches. */ Assert(list_length(best_path->indexclauses) == 1); scan_clauses = list_union_ptr(scan_clauses, - (List *) linitial(best_path->indexclauses)); + (List *) linitial(best_path->indexclauses)); } /* Reduce RestrictInfo list to bare expressions */ @@ -751,7 +751,7 @@ create_indexscan_plan(Query *root, stripped_indxquals = NIL; foreach(l, indxquals) { - List *andlist = (List *) lfirst(l); + List *andlist = (List *) lfirst(l); stripped_indxquals = lappend(stripped_indxquals, get_actual_clauses(andlist)); @@ -759,10 +759,10 @@ create_indexscan_plan(Query *root, /* * The qpqual list must contain all restrictions not automatically - * handled by the index. All the predicates in the indexquals will - * be checked (either by the index itself, or by nodeIndexscan.c), but - * if there are any "special" operators involved then they must be - * added to qpqual. The upshot is that qpquals must contain scan_clauses + * handled by the index. All the predicates in the indexquals will be + * checked (either by the index itself, or by nodeIndexscan.c), but if + * there are any "special" operators involved then they must be added + * to qpqual. The upshot is that qpquals must contain scan_clauses * minus whatever appears in indxquals. */ if (list_length(indxquals) > 1) @@ -770,7 +770,7 @@ create_indexscan_plan(Query *root, /* * Build an expression representation of the indexqual, expanding * the implicit OR and AND semantics of the first- and - * second-level lists. (The odds that this will exactly match any + * second-level lists. (The odds that this will exactly match any * scan_clause are not great; perhaps we need more smarts here.) */ indxqual_or_expr = make_expr_from_indexclauses(indxquals); @@ -1182,7 +1182,8 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path, Relids baserelids = index_path->path.parent->relids; int baserelid = index_path->path.parent->relid; List *index_info = index_path->indexinfo; - ListCell *iq, *ii; + ListCell *iq, + *ii; *fixed_indexquals = NIL; *indxstrategy = NIL; @@ -1211,7 +1212,7 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path, * * For each qual clause, commute if needed to put the indexkey operand on the * left, and then fix its varattno. (We do not need to change the other side - * of the clause.) Then determine the operator's strategy number and subtype + * of the clause.) Then determine the operator's strategy number and subtype * number, and check for lossy index behavior. * * Returns four lists: @@ -1247,7 +1248,7 @@ fix_indxqual_sublist(List *indexqual, Assert(IsA(rinfo, RestrictInfo)); clause = (OpExpr *) rinfo->clause; - if (!IsA(clause, OpExpr) || list_length(clause->args) != 2) + if (!IsA(clause, OpExpr) ||list_length(clause->args) != 2) elog(ERROR, "indexqual clause is not binary opclause"); /* @@ -1272,16 +1273,17 @@ fix_indxqual_sublist(List *indexqual, * indexkey operand as needed, and get the index opclass. */ linitial(newclause->args) = fix_indxqual_operand(linitial(newclause->args), - baserelid, - index, - &opclass); + baserelid, + index, + &opclass); *fixed_quals = lappend(*fixed_quals, newclause); /* - * Look up the (possibly commuted) operator in the operator class to - * get its strategy numbers and the recheck indicator. This also - * double-checks that we found an operator matching the index. + * Look up the (possibly commuted) operator in the operator class + * to get its strategy numbers and the recheck indicator. This + * also double-checks that we found an operator matching the + * index. */ get_op_opclass_properties(newclause->opno, opclass, &stratno, &stratsubtype, &recheck); @@ -1642,7 +1644,7 @@ make_append(List *appendplans, bool isTarget, List *tlist) { Plan *subplan = (Plan *) lfirst(subnode); - if (subnode == list_head(appendplans)) /* first node? */ + if (subnode == list_head(appendplans)) /* first node? */ plan->startup_cost = subplan->startup_cost; plan->total_cost += subplan->total_cost; plan->plan_rows += subplan->plan_rows; @@ -1837,7 +1839,10 @@ make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys) AttrNumber *sortColIdx; Oid *sortOperators; - /* We will need at most list_length(pathkeys) sort columns; possibly less */ + /* + * We will need at most list_length(pathkeys) sort columns; possibly + * less + */ numsortkeys = list_length(pathkeys); sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(AttrNumber)); sortOperators = (Oid *) palloc(numsortkeys * sizeof(Oid)); @@ -1876,8 +1881,8 @@ make_sort_from_pathkeys(Query *root, Plan *lefttree, List *pathkeys) /* No matching Var; look for a computable expression */ foreach(j, keysublist) { - List *exprvars; - ListCell *k; + List *exprvars; + ListCell *k; pathkey = (PathKeyItem *) lfirst(j); exprvars = pull_var_clause(pathkey->key, false); @@ -1948,7 +1953,10 @@ make_sort_from_sortclauses(Query *root, List *sortcls, Plan *lefttree) AttrNumber *sortColIdx; Oid *sortOperators; - /* We will need at most list_length(sortcls) sort columns; possibly less */ + /* + * We will need at most list_length(sortcls) sort columns; possibly + * less + */ numsortkeys = list_length(sortcls); sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(AttrNumber)); sortOperators = (Oid *) palloc(numsortkeys * sizeof(Oid)); @@ -2001,7 +2009,10 @@ make_sort_from_groupcols(Query *root, AttrNumber *sortColIdx; Oid *sortOperators; - /* We will need at most list_length(groupcls) sort columns; possibly less */ + /* + * We will need at most list_length(groupcls) sort columns; possibly + * less + */ numsortkeys = list_length(groupcls); sortColIdx = (AttrNumber *) palloc(numsortkeys * sizeof(AttrNumber)); sortOperators = (Oid *) palloc(numsortkeys * sizeof(Oid)); diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index c6124cda86a..ad9b9ac34c3 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.102 2004/08/29 04:12:33 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/initsplan.c,v 1.103 2004/08/29 05:06:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -451,8 +451,9 @@ distribute_qual_to_rels(Query *root, Node *clause, * tree. * * We also need to determine whether the qual is "valid everywhere", - * which is true if the qual mentions no variables that are involved - * in lower-level outer joins (this may be an overly strong test). + * which is true if the qual mentions no variables that are + * involved in lower-level outer joins (this may be an overly + * strong test). */ Relids addrelids = NULL; Relids tmprelids; @@ -706,7 +707,7 @@ process_implied_equality(Query *root, { /* delete it from local restrictinfo list */ rel1->baserestrictinfo = list_delete_ptr(rel1->baserestrictinfo, - restrictinfo); + restrictinfo); } else { diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 874f82ce16f..a6898e75c83 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.173 2004/08/29 04:12:33 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.174 2004/08/29 05:06:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,7 +43,7 @@ #include "utils/syscache.h" -ParamListInfo PlannerBoundParamList = NULL; /* current boundParams */ +ParamListInfo PlannerBoundParamList = NULL; /* current boundParams */ /* Expression kind codes for preprocess_expression */ @@ -88,10 +88,11 @@ planner(Query *parse, bool isCursor, int cursorOptions, * eval_const_expressions tries to pre-evaluate an SQL function). So, * these global state variables must be saved and restored. * - * Query level and the param list cannot be moved into the Query structure - * since their whole purpose is communication across multiple sub-Queries. - * Also, boundParams is explicitly info from outside the Query, and so - * is likewise better handled as a global variable. + * Query level and the param list cannot be moved into the Query + * structure since their whole purpose is communication across + * multiple sub-Queries. Also, boundParams is explicitly info from + * outside the Query, and so is likewise better handled as a global + * variable. * * Note we do NOT save and restore PlannerPlanId: it exists to assign * unique IDs to SubPlan nodes, and we want those IDs to be unique for @@ -391,9 +392,9 @@ preprocess_expression(Query *parse, Node *expr, int kind) expr = flatten_join_alias_vars(parse, expr); /* - * If it's a qual or havingQual, canonicalize it. It seems most useful - * to do this before applying eval_const_expressions, since the latter - * can optimize flattened AND/ORs better than unflattened ones. + * If it's a qual or havingQual, canonicalize it. It seems most + * useful to do this before applying eval_const_expressions, since the + * latter can optimize flattened AND/ORs better than unflattened ones. * * Note: all processing of a qual expression after this point must be * careful to maintain AND/OR flatness --- that is, do not generate a @@ -430,8 +431,8 @@ preprocess_expression(Query *parse, Node *expr, int kind) /* * If it's a qual or havingQual, convert it to implicit-AND format. * (We don't want to do this before eval_const_expressions, since the - * latter would be unable to simplify a top-level AND correctly. Also, - * SS_process_sublinks expects explicit-AND format.) + * latter would be unable to simplify a top-level AND correctly. + * Also, SS_process_sublinks expects explicit-AND format.) */ if (kind == EXPRKIND_QUAL) expr = (Node *) make_ands_implicit((Expr *) expr); @@ -585,7 +586,7 @@ grouping_planner(Query *parse, double tuple_fraction) if (parse->setOperations) { - List *set_sortclauses; + List *set_sortclauses; /* * Construct the plan for set operations. The result will not @@ -600,7 +601,7 @@ grouping_planner(Query *parse, double tuple_fraction) * the sort key information... */ current_pathkeys = make_pathkeys_for_sortclauses(set_sortclauses, - result_plan->targetlist); + result_plan->targetlist); current_pathkeys = canonicalize_pathkeys(parse, current_pathkeys); /* @@ -731,8 +732,8 @@ grouping_planner(Query *parse, double tuple_fraction) * * Note: think not that we can turn off hasAggs if we find no aggs. * It is possible for constant-expression simplification to remove - * all explicit references to aggs, but we still have to follow the - * aggregate semantics (eg, producing only one output row). + * all explicit references to aggs, but we still have to follow + * the aggregate semantics (eg, producing only one output row). */ if (parse->hasAggs) numAggs = count_agg_clause((Node *) tlist) + @@ -981,8 +982,8 @@ grouping_planner(Query *parse, double tuple_fraction) { /* * Use hashed grouping if (a) we think we can fit the - * hashtable into work_mem, *and* (b) the estimated cost is - * no more than doing it the other way. While avoiding + * hashtable into work_mem, *and* (b) the estimated cost + * is no more than doing it the other way. While avoiding * the need for sorted input is usually a win, the fact * that the output won't be sorted may be a loss; so we * need to do an actual cost comparison. @@ -1452,10 +1453,10 @@ make_subplanTargetList(Query *parse, foreach(gl, parse->groupClause) { - GroupClause *grpcl = (GroupClause *) lfirst(gl); - Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist); - TargetEntry *te = NULL; - ListCell *sl; + GroupClause *grpcl = (GroupClause *) lfirst(gl); + Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist); + TargetEntry *te = NULL; + ListCell *sl; /* Find or make a matching sub_tlist entry */ foreach(sl, sub_tlist) @@ -1513,10 +1514,10 @@ locate_grouping_columns(Query *parse, foreach(gl, parse->groupClause) { - GroupClause *grpcl = (GroupClause *) lfirst(gl); - Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist); - TargetEntry *te = NULL; - ListCell *sl; + GroupClause *grpcl = (GroupClause *) lfirst(gl); + Node *groupexpr = get_sortgroupclause_expr(grpcl, tlist); + TargetEntry *te = NULL; + ListCell *sl; foreach(sl, sub_tlist) { diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index 67d31c1b747..1a1ce9500cb 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.103 2004/08/29 04:12:33 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.104 2004/08/29 05:06:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -84,7 +84,7 @@ static void set_sa_opfuncid(ScalarArrayOpExpr *opexpr); void set_plan_references(Plan *plan, List *rtable) { - ListCell *l; + ListCell *l; if (plan == NULL) return; @@ -184,10 +184,11 @@ set_plan_references(Plan *plan, List *rtable) */ break; case T_Limit: + /* - * Like the plan types above, Limit doesn't evaluate its - * tlist or quals. It does have live expressions for - * limit/offset, however. + * Like the plan types above, Limit doesn't evaluate its tlist + * or quals. It does have live expressions for limit/offset, + * however. */ fix_expr_references(plan, ((Limit *) plan)->limitOffset); fix_expr_references(plan, ((Limit *) plan)->limitCount); @@ -213,11 +214,12 @@ set_plan_references(Plan *plan, List *rtable) fix_expr_references(plan, ((Result *) plan)->resconstantqual); break; case T_Append: + /* * Append, like Sort et al, doesn't actually evaluate its - * targetlist or quals, and we haven't bothered to give it - * its own tlist copy. So, don't fix targetlist/qual. But - * do recurse into child plans. + * targetlist or quals, and we haven't bothered to give it its + * own tlist copy. So, don't fix targetlist/qual. But do + * recurse into child plans. */ foreach(l, ((Append *) plan)->appendplans) set_plan_references((Plan *) lfirst(l), rtable); diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index 3a0abcfee8f..0b6008dc203 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.92 2004/08/29 04:12:33 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.93 2004/08/29 05:06:44 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -119,10 +119,10 @@ replace_outer_var(Var *var) * The correct field should get stored into the Param slot at * execution in each part of the tree. * - * We also need to demand a match on vartypmod. This does not matter - * for the Param itself, since those are not typmod-dependent, but it - * does matter when make_subplan() instantiates a modified copy of the - * Var for a subplan's args list. + * We also need to demand a match on vartypmod. This does not matter for + * the Param itself, since those are not typmod-dependent, but it does + * matter when make_subplan() instantiates a modified copy of the Var + * for a subplan's args list. */ i = 0; foreach(ppl, PlannerParamList) @@ -509,7 +509,9 @@ convert_sublink_opers(List *lefthand, List *operOids, List **righthandIds) { List *result = NIL; - ListCell *l, *lefthand_item, *tlist_item; + ListCell *l, + *lefthand_item, + *tlist_item; *righthandIds = NIL; lefthand_item = list_head(lefthand); @@ -533,8 +535,9 @@ convert_sublink_opers(List *lefthand, List *operOids, te->resdom->restype, te->resdom->restypmod, 0); + /* - * Copy it for caller. NB: we need a copy to avoid having + * Copy it for caller. NB: we need a copy to avoid having * doubly-linked substructure in the modified parse tree. */ *righthandIds = lappend(*righthandIds, copyObject(rightop)); @@ -616,8 +619,8 @@ subplan_is_hashable(SubLink *slink, SubPlan *node) return false; /* - * The estimated size of the subquery result must fit in work_mem. (XXX - * what about hashtable overhead?) + * The estimated size of the subquery result must fit in work_mem. + * (XXX what about hashtable overhead?) */ subquery_size = node->plan->plan_rows * (MAXALIGN(node->plan->plan_width) + MAXALIGN(sizeof(HeapTupleData))); @@ -746,8 +749,8 @@ convert_IN_to_join(Query *parse, SubLink *sublink) /* * Build the result qual expressions. As a side effect, - * ininfo->sub_targetlist is filled with a list of Vars - * representing the subselect outputs. + * ininfo->sub_targetlist is filled with a list of Vars representing + * the subselect outputs. */ exprs = convert_sublink_opers(sublink->lefthand, sublink->operOids, @@ -851,25 +854,25 @@ process_sublinks_mutator(Node *node, bool *isTopQual) /* * Because make_subplan() could return an AND or OR clause, we have to - * take steps to preserve AND/OR flatness of a qual. We assume the input - * has been AND/OR flattened and so we need no recursion here. + * take steps to preserve AND/OR flatness of a qual. We assume the + * input has been AND/OR flattened and so we need no recursion here. * - * If we recurse down through anything other than an AND node, - * we are definitely not at top qual level anymore. (Due to the coding - * here, we will not get called on the List subnodes of an AND, so no - * check is needed for List.) + * If we recurse down through anything other than an AND node, we are + * definitely not at top qual level anymore. (Due to the coding here, + * we will not get called on the List subnodes of an AND, so no check + * is needed for List.) */ if (and_clause(node)) { - List *newargs = NIL; - ListCell *l; + List *newargs = NIL; + ListCell *l; /* Still at qual top-level */ locTopQual = *isTopQual; foreach(l, ((BoolExpr *) node)->args) { - Node *newarg; + Node *newarg; newarg = process_sublinks_mutator(lfirst(l), (void *) &locTopQual); @@ -886,12 +889,12 @@ process_sublinks_mutator(Node *node, bool *isTopQual) if (or_clause(node)) { - List *newargs = NIL; - ListCell *l; + List *newargs = NIL; + ListCell *l; foreach(l, ((BoolExpr *) node)->args) { - Node *newarg; + Node *newarg; newarg = process_sublinks_mutator(lfirst(l), (void *) &locTopQual); @@ -1035,7 +1038,7 @@ finalize_plan(Plan *plan, List *rtable, case T_Append: { - ListCell *l; + ListCell *l; foreach(l, ((Append *) plan)->appendplans) { |