pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@postgresql.org
Subject: pgsql: Expression evaluation based aggregate transition invocation.
Date: Tue, 09 Jan 2018 21:48:14 +0000
Message-ID: <E1eZ1kk-0001u1-Pi@gemulon.postgresql.org> (raw)

Expression evaluation based aggregate transition invocation.

Previously aggregate transition and combination functions were invoked
by special case code in nodeAgg.c, evaluating 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, as
  commonly there are multiple aggregates in a query, resulting in the
  same call-stack invoking different functions.
- 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.

There's potential for further improvement:
- It'd be nice if we could simplify the somewhat expensive
  aggstate->all_pergroups lookups.
- right now there's still an advance_transition_function invocation in
  nodeAgg.c, leading to some code duplication.

Author: Andres Freund
Discussion: https://postgr.es/m/20170901064131.tazjxwus3k2w3ybh@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/69c3936a1499b772a749ae629fc59b2d72722332

Modified Files
--------------
src/backend/executor/execExpr.c       | 429 ++++++++++++++++-
src/backend/executor/execExprInterp.c | 356 +++++++++++++-
src/backend/executor/nodeAgg.c        | 864 ++++------------------------------
src/include/executor/execExpr.h       |  76 ++-
src/include/executor/executor.h       |   4 +-
src/include/executor/nodeAgg.h        | 284 +++++++++++
src/include/nodes/execnodes.h         |   5 +-
src/tools/pgindent/typedefs.list      |   1 +
8 files changed, 1230 insertions(+), 789 deletions(-)



Message-ID: <E1eZ1kk-0001u1-Pi@gemulon.postgresql.org>
Permalink:  ../E1eZ1kk-0001u1-Pi@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1eZ1kk-0001u1-Pi@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: pgsql: Expression evaluation based aggregate transition invocation.
  In-Reply-To: <E1eZ1kk-0001u1-Pi@gemulon.postgresql.org>
  References: <E1eZ1kk-0001u1-Pi@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox