X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2A0CB11F8C9E for ; Mon, 24 Apr 2006 15:47:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 61799-01-7 for ; Mon, 24 Apr 2006 15:47:01 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.233]) by postgresql.org (Postfix) with ESMTP id 46BD311F9506 for ; Mon, 24 Apr 2006 11:36:22 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i32so900547wra for ; Mon, 24 Apr 2006 07:36:23 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:cc:subject:date:organization:mime-version:content-type:content-transfer-encoding:x-mailer:in-reply-to:x-mimeole:thread-index:message-id; b=Bnf7LHINcQNotyjSBjEgy8JDjAcJLQ0rA3wKDLp7//FT2CfxP7wn7Dx29dbYOe5U/FmDDkH7XKP6iyIPaRKs1J5bND40Pv5aPTmSCE+EqrV+5xBxZhOHLUXoXqGH5bQEHVi8qJrnsghocrsqry5DN3RZRD6Ch3/9QgUesBHupI4= Received: by 10.54.67.6 with SMTP id p6mr4769861wra; Mon, 24 Apr 2006 07:36:23 -0700 (PDT) Received: from sbew318anc22 ( [200.157.135.150]) by mx.gmail.com with ESMTP id 24sm2702056wrl.2006.04.24.07.36.22; Mon, 24 Apr 2006 07:36:22 -0700 (PDT) From: "Bruno Almeida do Lago" To: "'Tom Lane'" Cc: Subject: Re: GROUP BY Vs. Sub SELECT Date: Mon, 24 Apr 2006 11:36:18 -0300 Organization: G&P MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook, Build 11.0.6353 In-Reply-To: <18881.1145835264@sss.pgh.pa.us> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Thread-Index: AcZnLnVB6UHho65rRDeqBANJ7XWvYQAfUoVg Message-ID: <444ce266.1ca74910.7370.ffffe386@mx.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/526 X-Sequence-Number: 18610 OK! I totally understand what you said. I'll load this table with a simulated data and see how PG deals with it. About the queries being different, yes, I'm sure they are :-) I did not mention that application is able to handle both. I'd like to get more info on EXPLAIN ANALYZE output... where can I read more about it? Thank you very much for your attention!! Regards, Bruno -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us] Sent: Sunday, April 23, 2006 8:34 PM To: Bruno Almeida do Lago Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] GROUP BY Vs. Sub SELECT "Bruno Almeida do Lago" writes: > I'm just getting familiar with EXPLAIN ANALYZE output, so I'd like to get > some help to identify which one of the following queries would be better: Well, you're breaking one of the first laws of PG performance analysis, which is to not try to extrapolate the behavior on large tables from the behavior on toy tables. You can't really see where the bottlenecks are on a toy example, and what's more there's no reason to think that the planner will use the same plan when presented with much larger tables. So you need to load up a meaningful amount of data (don't forget to ANALYZE afterward!) and then see what it does. > I think 2nd would be better, since when database grow up the GROUP BY may > become too costly. Is that right? The two queries don't give the same answer, so asking which is faster is a bit irrelevant. (When there's more than one group, wouldn't the per-group MAXes be different?) regards, tom lane