pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <david.rowley@2ndquadrant.com>
Cc: pgsql-hackers@postgreSQL.org
Subject: Rethinking representation of partial-aggregate steps
Date: Thu, 23 Jun 2016 12:26:00 -0400
Message-ID: <29309.1466699160@sss.pgh.pa.us> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

I really dislike this aspect of the partial-aggregate patch:

typedef struct Agg
{
    ...
    bool        combineStates;  /* input tuples contain transition states */
    bool        finalizeAggs;   /* should we call the finalfn on agg states? */
    bool        serialStates;   /* should agg states be (de)serialized? */
    ...
} Agg;

Representing the various partial-aggregate behaviors as three bools seems
like a bad idea to me.  In the first place, this makes it look like there
are as many as eight possible behaviors, whereas only a subset of those
flag combinations are or ever will be supported (not that the comments
anywhere tell you that, much less which ones).  In the second place,
it leads to unreadable code like this:

            /* partial phase */
            count_agg_clauses(root, (Node *) partial_grouping_target->exprs,
                              &agg_partial_costs, false, false, true);

            /* final phase */
            count_agg_clauses(root, (Node *) target->exprs, &agg_final_costs,
                              true, true, true);
            count_agg_clauses(root, parse->havingQual, &agg_final_costs, true,
                              true, true);

Good luck telling whether those falses and trues actually do what they
should.

I'm inclined to think that we should aggressively simplify here, perhaps
replacing all three of these flags with a three-way enum, say

	PARTIALAGG_NORMAL	/* simple aggregation */
	PARTIALAGG_PARTIAL	/* lower phase of partial aggregation */
	PARTIALAGG_FINAL	/* upper phase of partial aggregation */

This embodies a couple of judgments that maybe someone would quibble with:
* we don't have any use for intermediate partial aggregation steps;
* we don't have any use for partial aggregation in which data transferred
up needn't be serialized.

But I can't really see how either of those would make sense for any
practical use-case, and I don't think we need to have a confusing and
bug-prone API in order to hold the door open to support them.

Comments?

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (22+ messages)  latest in thread

Message-ID: <29309.1466699160@sss.pgh.pa.us>
Permalink:  ../29309.1466699160@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29309.1466699160@sss.pgh.pa.us

 · 

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-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.rowley@2ndquadrant.com
  Subject: Re: Rethinking representation of partial-aggregate steps
  In-Reply-To: <29309.1466699160@sss.pgh.pa.us>
  References: <29309.1466699160@sss.pgh.pa.us>

* 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