Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit804163b

Browse files
committed
Share transition state between different aggregates when possible.
If there are two different aggregates in the query with same inputs, andthe aggregates have the same initial condition and transition function,only calculate the state value once, and only call the final functionsseparately. For example, AVG(x) and SUM(x) aggregates have the sametransition function, which accumulates the sum and number of input tuples.For a query like "SELECT AVG(x), SUM(x) FROM x", we can thereforeaccumulate the state function only once, which gives a nice speedup.David Rowley, reviewed and edited by me.
1 parentdee0200 commit804163b

File tree

8 files changed

+1132
-457
lines changed

8 files changed

+1132
-457
lines changed

‎src/backend/executor/execQual.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4487,35 +4487,15 @@ ExecInitExpr(Expr *node, PlanState *parent)
44874487
break;
44884488
caseT_Aggref:
44894489
{
4490-
Aggref*aggref= (Aggref*)node;
44914490
AggrefExprState*astate=makeNode(AggrefExprState);
44924491

44934492
astate->xprstate.evalfunc= (ExprStateEvalFunc)ExecEvalAggref;
44944493
if (parent&&IsA(parent,AggState))
44954494
{
44964495
AggState*aggstate= (AggState*)parent;
4497-
intnaggs;
44984496

44994497
aggstate->aggs=lcons(astate,aggstate->aggs);
4500-
naggs=++aggstate->numaggs;
4501-
4502-
astate->aggdirectargs= (List*)ExecInitExpr((Expr*)aggref->aggdirectargs,
4503-
parent);
4504-
astate->args= (List*)ExecInitExpr((Expr*)aggref->args,
4505-
parent);
4506-
astate->aggfilter=ExecInitExpr(aggref->aggfilter,
4507-
parent);
4508-
4509-
/*
4510-
* Complain if the aggregate's arguments contain any
4511-
* aggregates; nested agg functions are semantically
4512-
* nonsensical. (This should have been caught earlier,
4513-
* but we defend against it here anyway.)
4514-
*/
4515-
if (naggs!=aggstate->numaggs)
4516-
ereport(ERROR,
4517-
(errcode(ERRCODE_GROUPING_ERROR),
4518-
errmsg("aggregate function calls cannot be nested")));
4498+
aggstate->numaggs++;
45194499
}
45204500
else
45214501
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp