Re: queries with DISTINCT / GROUP BY giving different plans

From: Tomas Vondra <tv(at)fuzzy(dot)cz>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: queries with DISTINCT / GROUP BY giving different plans
Date: 2013-08-20 15:13:09
Message-ID: 52138785.8010607@fuzzy.cz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 16.8.2013 21:36, Tomas Vondra wrote:
>
> Now, the difference between 24 and 56 is caused by hash_agg_entry_size.
> It's called with numAggs=0 but returns 32. I'm wondering if it should
> return 0 in such cases, i.e. something like this:
>
> Size
> hash_agg_entry_size(int numAggs)
> {
> Size entrysize;
>
> if (numAggs == 0)
> return 0;
>
> /* This must match build_hash_table */
> entrysize = sizeof(AggHashEntryData) +
> (numAggs - 1) * sizeof(AggStatePerGroupData);
> entrysize = MAXALIGN(entrysize);
> /* Account for hashtable overhead (assuming fill factor = 1) */
> entrysize += 3 * sizeof(void *);
> return entrysize;
> }
>
> I've tested that after this both queries use HashAggregate (which is the
> right choice), but I haven't done any extensive checking so maybe I'm
> missing something.

So, is this a sufficient / correct explanation? Any comments about the
fix I suggested? Or should I try to get a permission to provide the data
so that you can reproduce the issue on your own? That might take a few
days to get through.

Tomas

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2013-08-20 16:24:56 Re: queries with DISTINCT / GROUP BY giving different plans
Previous Message amulsul 2013-08-20 07:13:56 Re: DBT5 execution failed due to undefined symbol: PQescapeLiteral