Re: Why count(*) doest use index?

Поиск
Список
Период
Сортировка
От Igor Neyman
Тема Re: Why count(*) doest use index?
Дата
Msg-id F4C27E77F7A33E4CA98C19A9DC6722A2073C2C13@EXCHANGE.corp.perceptron.com
обсуждение исходный текст
Ответ на Re: Why count(*) doest use index?  (Glenn Maynard <glenn@zewt.org>)
Ответы Re: Why count(*) doest use index?
Список pgsql-general
> -----Original Message-----
> From: Glenn Maynard [mailto:glenn@zewt.org]
> Sent: Monday, March 07, 2011 5:27 PM
> To: pgsql-general@postgresql.org
> Subject: Re: Why count(*) doest use index?
>
>
> An index on "events(user, event_time::date)" could optimize
> this, eg. effectively maintaining a count of matching rows
> for each (user, day) tuple--which is ultimately what I'm
> doing manually with triggers.  Of course, it would have a
> significant cost, in some combination of complexity, index
> size and write concurrency, and couldn't be the default
> behavior for an index.
>
> --
> Glenn Maynard
>

Indexes don't "maintain counts", indexes maintain pointers to the table
records.

What you need is "materialized view" storing aggregates.
And it looks like you already have it with your triggers.

Regards,
Igor Neyman

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

Предыдущее
От: Raymond O'Donnell
Дата:
Сообщение: Re: NULL value vs. DEFAULT value.
Следующее
От: "David Johnston"
Дата:
Сообщение: Re: NULL value vs. DEFAULT value.