Обсуждение: count(*) index

Поиск
Список
Период
Сортировка

count(*) index

От
Tomka Gergely
Дата:
Hi!

Yes, i know, mvcc, and can't use indexes. And i know the workaround for
max() and min(). Is there some workaround for count()?

select count(*) from table where field=1;

and field has a nice index. And this is slooooow.

--
Tomka Gergely
Tudom, anyu. Sapka, sál, doksi.

Re: count(*) index

От
Bruno Wolff III
Дата:
On Fri, Jan 07, 2005 at 19:22:56 +0100,
  Tomka Gergely <tomka@zeus.gau.hu> wrote:
> Hi!
>
> Yes, i know, mvcc, and can't use indexes. And i know the workaround for
> max() and min(). Is there some workaround for count()?
>
> select count(*) from table where field=1;
>
> and field has a nice index. And this is slooooow.

If there are few records where field=1 then an index will be used.

You may get better performance maintaining a count table using triggers.
This may not work well of there are lots of concurrent updates.