Re: Make COUNT(*) Faster?

Поиск
Список
Период
Сортировка
От Rod Taylor
Тема Re: Make COUNT(*) Faster?
Дата
Msg-id 1120837111.24708.252.camel@home
обсуждение исходный текст
Ответ на Re: Make COUNT(*) Faster?  (Dawid Kuroczko <qnex42@gmail.com>)
Список pgsql-sql
On Fri, 2005-07-08 at 17:34 +0200, Dawid Kuroczko wrote:
> On 7/8/05, Rod Taylor <pg@rbt.ca> wrote:
> > Create 2 sequences, one for counting tuple additions and one for
> > counting tuple deletions.
> > 
> > When you INSERT a tuple, bump the "added" sequence (select nextval());
> > 
> > When you DELETE a tuple, bump the "deleted" sequence (select nextval());
> > 
> > To retrieve an approximate count, take the current value of both
> > sequences (select directly -- don't use currval) and subtract the
> > "deletes" from the "adds".
> 
> Never thought of that!  Good idea. :-)
> 
>    Regards,
>       Dawid
> 
> PS: There aren't any on ROLLBACK triggers, right? ;-)))

No. You could make then RI triggers and have them deferred until commit
though.

-- 



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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Make COUNT(*) Faster?
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: two sums in one query