X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fbackend%2Foptimizer%2Fpath%2Fcostsize.c;h=7f30dde869f31faa0c98c08fee27752364d94fac;hb=95b07bc7f5010233f52f9d11da74e2e5b653b0a7;hp=0b9c5819820274de0fc52a30487de106c7f6c05f;hpb=38e9348282e9d078487147ba8a85aebec54e3a08;p=pg-rex%2Fsyncrep.git diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 0b9c581982..7f30dde869 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -54,7 +54,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.201 2008/11/22 22:47:05 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/costsize.c,v 1.202 2008/12/28 18:53:56 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1284,6 +1284,40 @@ cost_agg(Path *path, PlannerInfo *root, } /* + * cost_windowagg + * Determines and returns the cost of performing a WindowAgg plan node, + * including the cost of its input. + * + * Input is assumed already properly sorted. + */ +void +cost_windowagg(Path *path, PlannerInfo *root, + int numWindowFuncs, int numPartCols, int numOrderCols, + Cost input_startup_cost, Cost input_total_cost, + double input_tuples) +{ + Cost startup_cost; + Cost total_cost; + + startup_cost = input_startup_cost; + total_cost = input_total_cost; + + /* + * We charge one cpu_operator_cost per window function per tuple (often a + * drastic underestimate, but without a way to gauge how many tuples the + * window function will fetch, it's hard to do better). We also charge + * cpu_operator_cost per grouping column per tuple for grouping + * comparisons, plus cpu_tuple_cost per tuple for general overhead. + */ + total_cost += cpu_operator_cost * input_tuples * numWindowFuncs; + total_cost += cpu_operator_cost * input_tuples * (numPartCols + numOrderCols); + total_cost += cpu_tuple_cost * input_tuples; + + path->startup_cost = startup_cost; + path->total_cost = total_cost; +} + +/* * cost_group * Determines and returns the cost of performing a Group plan node, * including the cost of its input. @@ -2155,6 +2189,11 @@ cost_qual_eval_walker(Node *node, cost_qual_eval_context *context) * Vars and Consts are charged zero, and so are boolean operators (AND, * OR, NOT). Simplistic, but a lot better than no model at all. * + * Note that Aggref and WindowFunc nodes are (and should be) treated + * like Vars --- whatever execution cost they have is absorbed into + * plan-node-specific costing. As far as expression evaluation is + * concerned they're just like Vars. + * * Should we try to account for the possibility of short-circuit * evaluation of AND/OR? Probably *not*, because that would make the * results depend on the clause ordering, and we are not in any position