Re: Grouping Too Closely

Поиск
Список
Период
Сортировка
От Russell Simpkins
Тема Re: Grouping Too Closely
Дата
Msg-id BAY103-F8E562EE568057C24D58B9B5EA0@phx.gbl
обсуждение исходный текст
Ответ на Grouping Too Closely  ("Thomas F. O'Connell" <tfo@sitening.com>)
Список 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




В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: optimizer, view, union
Следующее
От: Markus Bertheau
Дата:
Сообщение: empty view, replace view, column type change?