pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Bruno Almeida do Lago <teolupus@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: GROUP BY Vs. Sub SELECT
Date: Sun, 23 Apr 2006 19:34:24 -0400
Message-ID: <18881.1145835264@sss.pgh.pa.us> (raw)
In-Reply-To: <444bea48.5e66e367.75a4.0537@mx.gmail.com>
References: <444bea48.5e66e367.75a4.0537@mx.gmail.com>

"Bruno Almeida do Lago" <teolupus@gmail.com> 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



view thread (5+ messages)  latest in thread

Message-ID: <18881.1145835264@sss.pgh.pa.us>
Permalink:  ../18881.1145835264@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18881.1145835264@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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, teolupus@gmail.com
  Subject: Re: GROUP BY Vs. Sub SELECT
  In-Reply-To: <18881.1145835264@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