mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Improve cost estimation for aggregates and window functions.
The previous coding failed to account properly for the costs of evaluating the input expressions of aggregates and window functions, as seen in a recent gripe from Claudio Freire. (I said at the time that it wasn't counting these costs at all; but on closer inspection, it was effectively charging these costs once per output tuple. That is completely wrong for aggregates, and not exactly right for window functions either.) There was also a hard-wired assumption that aggregates and window functions had procost 1.0, which is now fixed to respect the actual cataloged costs. The costing of WindowAgg is still pretty bogus, since it doesn't try to estimate the effects of spilling data to disk, but that seems like a separate issue.
This commit is contained in:
@@ -20,13 +20,6 @@
|
||||
#define is_opclause(clause) ((clause) != NULL && IsA(clause, OpExpr))
|
||||
#define is_funcclause(clause) ((clause) != NULL && IsA(clause, FuncExpr))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int numAggs; /* total number of aggregate calls */
|
||||
int numOrderedAggs; /* number that use DISTINCT or ORDER BY */
|
||||
Size transitionSpace; /* for pass-by-ref transition data */
|
||||
} AggClauseCounts;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int numWindowFuncs; /* total number of WindowFuncs found */
|
||||
@@ -56,7 +49,8 @@ extern List *make_ands_implicit(Expr *clause);
|
||||
|
||||
extern bool contain_agg_clause(Node *clause);
|
||||
extern List *pull_agg_clause(Node *clause);
|
||||
extern void count_agg_clauses(Node *clause, AggClauseCounts *counts);
|
||||
extern void count_agg_clauses(PlannerInfo *root, Node *clause,
|
||||
AggClauseCosts *costs);
|
||||
|
||||
extern bool contain_window_function(Node *clause);
|
||||
extern WindowFuncLists *find_window_functions(Node *clause, Index maxWinRef);
|
||||
|
||||
@@ -94,12 +94,12 @@ extern void cost_material(Path *path,
|
||||
Cost input_startup_cost, Cost input_total_cost,
|
||||
double tuples, int width);
|
||||
extern void cost_agg(Path *path, PlannerInfo *root,
|
||||
AggStrategy aggstrategy, int numAggs,
|
||||
AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
|
||||
int numGroupCols, double numGroups,
|
||||
Cost input_startup_cost, Cost input_total_cost,
|
||||
double input_tuples);
|
||||
extern void cost_windowagg(Path *path, PlannerInfo *root,
|
||||
int numWindowFuncs, int numPartCols, int numOrderCols,
|
||||
List *windowFuncs, int numPartCols, int numOrderCols,
|
||||
Cost input_startup_cost, Cost input_total_cost,
|
||||
double input_tuples);
|
||||
extern void cost_group(Path *path, PlannerInfo *root,
|
||||
|
||||
@@ -34,7 +34,7 @@ extern void query_planner(PlannerInfo *root, List *tlist,
|
||||
*/
|
||||
extern void preprocess_minmax_aggregates(PlannerInfo *root, List *tlist);
|
||||
extern Plan *optimize_minmax_aggregates(PlannerInfo *root, List *tlist,
|
||||
Path *best_path);
|
||||
const AggClauseCosts *aggcosts, Path *best_path);
|
||||
|
||||
/*
|
||||
* prototypes for plan/createplan.c
|
||||
@@ -54,12 +54,12 @@ extern Sort *make_sort_from_sortclauses(PlannerInfo *root, List *sortcls,
|
||||
extern Sort *make_sort_from_groupcols(PlannerInfo *root, List *groupcls,
|
||||
AttrNumber *grpColIdx, Plan *lefttree);
|
||||
extern Agg *make_agg(PlannerInfo *root, List *tlist, List *qual,
|
||||
AggStrategy aggstrategy,
|
||||
AggStrategy aggstrategy, const AggClauseCosts *aggcosts,
|
||||
int numGroupCols, AttrNumber *grpColIdx, Oid *grpOperators,
|
||||
long numGroups, int numAggs,
|
||||
long numGroups,
|
||||
Plan *lefttree);
|
||||
extern WindowAgg *make_windowagg(PlannerInfo *root, List *tlist,
|
||||
int numWindowFuncs, Index winref,
|
||||
List *windowFuncs, Index winref,
|
||||
int partNumCols, AttrNumber *partColIdx, Oid *partOperators,
|
||||
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators,
|
||||
int frameOptions, Node *startOffset, Node *endOffset,
|
||||
|
||||
Reference in New Issue
Block a user