Lists: | Postg토토 꽁 머니SQL |
---|
From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Expression based aggregate transition / combine function invocation |
Date: | 2017-11-28 00:31:21 |
Message-ID: | 20171128003121.nmxbm2ounxzb6n2t@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi,
this is part of my work to make expression evaluation JITable. In a lot
of analytics queries the major bottleneck is transition function
invocation (makes sense, hardly anyone wants to see billions of
rows). Therefore for JITing to be really valuable transition function
stuff needs to be JITable.
Excerpt from the preliminary commit message:
Previously aggregate transition and combination functions were invoked
by special case code in nodeAgg.c, evaluting input and filters
separately using the expression evaluation machinery. That turns out
to not be great for performance for several reasons:
- repeated expression evaluations have some cost
- the transition functions invocations are poorly predicted
- filter and input computation had to be done separately
- the special case code made it hard to implement JITing of the whole
transition function invocation
Address this by building one large expression that computes input,
evaluates filters, and invokes transition functions.
This leads to moderate speedups in queries bottlenecked by aggregate
computations, and enables large speedups for similar cases once JITing
is done.
While this gets rid of a substantial amount of duplication between the
infrastructure for transition and combine functions, it still increases
codesize a bit.
Todo / open Questions:
- Location of transition function building functions. Currently they're
in execExpr.c. That allows not to expose a bunch of functions local to
it, but requires exposing some aggregate structs to the world. We
could go the other way round as well.
- Right now we waste a bunch of time by having to access transition
states indexed by both grouping set number and the transition state
offset therein. It'd be nicer if we could cheaply reduce the number of
indirections, but I can't quite see how without adding additional
complications.
Here's some example tpch Q01 timings:
master: 11628 ms (best of three)
patches: 10330 ms (best of three)
other tpch queries are similar, aggregate improvement is a factor of
x 1.04.
Greetings,
Andres Freund
Attachment | Content-Type | Size |
---|---|---|
0001-Simplify-representation-of-aggregate-transition-valu.patch | text/x-diff | 10.0 KB |
0002-More-efficient-AggState-pertrans-iteration.patch | text/x-diff | 4.2 KB |
0003-Expression-evaluatation-based-agg-transition-invocat.patch | text/x-diff | 74.3 KB |
From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Expression based aggregate transition / combine function invocation |
Date: | 2018-01-07 23:00:25 |
Message-ID: | 20180107230025.vrgim3yb3yb2oj4q@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
Hi,
On 2017-11-27 16:31:21 -0800, Andres Freund wrote:
> this is part of my work to make expression evaluation JITable. In a lot
> of analytics queries the major bottleneck is transition function
> invocation (makes sense, hardly anyone wants to see billions of
> rows). Therefore for JITing to be really valuable transition function
> stuff needs to be JITable.
>
> Excerpt from the preliminary commit message:
>
> Previously aggregate transition and combination functions were invoked
> by special case code in nodeAgg.c, evaluting input and filters
> separately using the expression evaluation machinery. That turns out
> to not be great for performance for several reasons:
> - repeated expression evaluations have some cost
> - the transition functions invocations are poorly predicted
> - filter and input computation had to be done separately
> - the special case code made it hard to implement JITing of the whole
> transition function invocation
>
> Address this by building one large expression that computes input,
> evaluates filters, and invokes transition functions.
>
> This leads to moderate speedups in queries bottlenecked by aggregate
> computations, and enables large speedups for similar cases once JITing
> is done.
> While this gets rid of a substantial amount of duplication between the
> infrastructure for transition and combine functions, it still increases
> codesize a bit.
There's still two callers of advance_transition_function() left, namely
process_ordered_aggregate_{single,multi}. Rearchitecting this so they
also go through expression-ified transition invocation seems like
material for a separate patch, this is complicated enough...
> Todo / open Questions:
> - Location of transition function building functions. Currently they're
> in execExpr.c. That allows not to expose a bunch of functions local to
> it, but requires exposing some aggregate structs to the world. We
> could go the other way round as well.
I've left this as is.
> - Right now we waste a bunch of time by having to access transition
> states indexed by both grouping set number and the transition state
> offset therein. It'd be nicer if we could cheaply reduce the number of
> indirections, but I can't quite see how without adding additional
> complications.
I've left this as is.
Here's a considerably polished variant of this patch. I plan to do
another round of polishing next week, and then push it, unless somebody
else has comments.
Regards,
Andres
From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Expression based aggregate transition / combine function invocation |
Date: | 2018-01-07 23:01:37 |
Message-ID: | 20180107230137.kwuklr3fdufgumm4@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | Postg토토 꽁 머니SQL |
> Here's a considerably polished variant of this patch.
And for realz.
Attachment | Content-Type | Size |
---|---|---|
0001-Expression-evaluatation-based-agg-transition-invocat.patch | text/x-diff | 78.8 KB |