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 CE21111F6085 for ; Sun, 23 Apr 2006 20:34:32 -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 22075-01 for ; Sun, 23 Apr 2006 20:34:29 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 3E37511F6081 for ; Sun, 23 Apr 2006 20:34:27 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k3NNYP3s018882; Sun, 23 Apr 2006 19:34:25 -0400 (EDT) To: "Bruno Almeida do Lago" cc: pgsql-performance@postgresql.org Subject: Re: GROUP BY Vs. Sub SELECT In-reply-to: <444bea48.5e66e367.75a4.0537@mx.gmail.com> References: <444bea48.5e66e367.75a4.0537@mx.gmail.com> Comments: In-reply-to "Bruno Almeida do Lago" message dated "Sun, 23 Apr 2006 17:57:40 -0300" Date: Sun, 23 Apr 2006 19:34:24 -0400 Message-ID: <18881.1145835264@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/516 X-Sequence-Number: 18600 "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