Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VBncV-0003R7-Lm for pgsql-performance@arkaria.postgresql.org; Tue, 20 Aug 2013 15:13:19 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VBncU-0000s4-Qo for pgsql-performance@arkaria.postgresql.org; Tue, 20 Aug 2013 15:13:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VBncU-0000ry-1l for pgsql-performance@postgresql.org; Tue, 20 Aug 2013 15:13:18 +0000 Received: from mail.gransy.com ([2001:1528:137::f1]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VBncQ-0000VS-Mm for pgsql-performance@postgresql.org; Tue, 20 Aug 2013 15:13:17 +0000 Received: from antispam.gransy.com (antispam.gransy.com [77.78.104.124]) by mail.gransy.com (Postfix) with ESMTP id 43DEA508BCF for ; Tue, 20 Aug 2013 17:13:10 +0200 (CEST) X-Virus-Scanned: G-Hosting.cz + Station.cz + Klenot.cz + Subreg.cz amavisd-new at antispam.gransy.com Received: from mail.gransy.com ([82.208.44.189]) by antispam.gransy.com (antispam.gransy.com [77.78.104.124]) (amavisd-new, port 10024) with ESMTP id LUWsDNdoJ_30 for ; Tue, 20 Aug 2013 17:13:19 +0200 (CEST) Received: by mail.gransy.com (Postfix, from userid 5000) id 02EA4508C19; Tue, 20 Aug 2013 17:13:09 +0200 (CEST) Received: from [192.168.1.237] (ip-78-45-139-138.net.upcbroadband.cz [78.45.139.138]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.gransy.com (Postfix) with ESMTPSA id DC76E508C14 for ; Tue, 20 Aug 2013 17:13:09 +0200 (CEST) Message-ID: <52138785.8010607@fuzzy.cz> Date: Tue, 20 Aug 2013 17:13:09 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: queries with DISTINCT / GROUP BY giving different plans References: <3a56c4d2c0b2daa11a625c2983823901.squirrel@sq.gransy.com> <11586.1376505314@sss.pgh.pa.us> <520E7F33.7010305@fuzzy.cz> In-Reply-To: <520E7F33.7010305@fuzzy.cz> Content-Type: text/plain; charset=ISO-8859-2 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org 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 -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance