From: | "Russell Simpkins" <russellsimpkins(at)hotmail(dot)com> |
---|---|
To: | tfo(at)sitening(dot)com, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Grouping Too Closely |
Date: | 2005-06-23 20:03:45 |
Message-ID: | BAY103-F8E562EE568057C24D58B9B5EA0@phx.gbl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Rod Taylor | 2005-06-23 20:19:44 | Re: empty view, replace view, column type change? |
Previous Message | Markus Bertheau | 2005-06-23 20:03:29 | empty view, replace view, column type change? |