pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Russell Simpkins <russellsimpkins@hotmail.com>
To: tfo@sitening.com
To: pgsql-sql@postgresql.org
Subject: Re: Grouping Too Closely
Date: Thu, 23 Jun 2005 16:03:45 -0400
Message-ID: <BAY103-F8E562EE568057C24D58B9B5EA0@phx.gbl> (raw)
In-Reply-To: <BBA34C36-E1D7-4166-A47F-BA0D563C48B9@sitening.com>

I'm not sure if this is the best thing to do in all occasions, but I have 
found a great speed increase using unions over group by.

select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 = ( select 
min(seq1) from mytable);
union
select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 = ( select 
min(seq1) from mytable);
order by fkey, uid, seq2;

the union clause with remove your duplicates for you as you were doing with 
your group by.

using min on large tables can cause problems. you may want to do your select 
min(seq1) from mytable or even have a trigger function after insert/update 
that checks the new value against the current lowest stored in another 
table.

not sure if this helps, but i hope it does.

russ





view thread (5+ messages)  latest in thread

Message-ID: <BAY103-F8E562EE568057C24D58B9B5EA0@phx.gbl>
Permalink:  ../BAY103-F8E562EE568057C24D58B9B5EA0@phx.gbl/
Also on:    postgresql.org/message-id/BAY103-F8E562EE568057C24D58B9B5EA0@phx.gbl

 · 

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-sql@postgresql.org
  Cc: russellsimpkins@hotmail.com, tfo@sitening.com
  Subject: Re: Grouping Too Closely
  In-Reply-To: <BAY103-F8E562EE568057C24D58B9B5EA0@phx.gbl>

* 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