Re: no index-usage on aggregate-functions?

От: Dennis Bjorklund
Тема: Re: no index-usage on aggregate-functions?
Дата: ,
Msg-id: Pine.LNX.4.44.0406291337130.21809-100000@zigo.dhs.org
(см: обсуждение, исходный текст)
Ответ на: Re: no index-usage on aggregate-functions?  ("Harald Lau (Sector-X)")
Список: pgsql-performance

Скрыть дерево обсуждения

no index-usage on aggregate-functions?  ("Harald Lau (Sector-X)", )
 Re: no index-usage on aggregate-functions?  ("Scott Marlowe", )
 Re: no index-usage on aggregate-functions?  (Christopher Kings-Lynne, )
 Re: no index-usage on aggregate-functions?  ("Harald Lau (Sector-X)", )
  Re: no index-usage on aggregate-functions?  (Dennis Bjorklund, )
  Re: no index-usage on aggregate-functions?  (Bruno Wolff III, )
  Re: no index-usage on aggregate-functions?  ("Scott Marlowe", )
 Re: no index-usage on aggregate-functions?  ("Harald Lau (Sector-X)", )

On Tue, 29 Jun 2004, Harald Lau (Sector-X) wrote:

> > Average and sum can never use an index AFAIK, in any db server.  You
> > need information from every row.
>
> Take a look at the SQLSrv-pendant:
> create index x_1 on the_table (num_found)
> select avg(num_found) from the_table
> -> Index Scan(OBJECT:([midata].[dbo].[THE_TABLE].[x_1])

But is it really faster is the question?

This sum needs all the values in that column. As far as I know it uses the
index because it uses less space on disk and thus is a little faster due
to less IO. In pg the index doesn't work like that, so in pg it's faster
to sum all values using the table itself.

If you have a WHERE clause to only sum some values, then pg will use an
index (if applicable) and you will see a speedup.

For min and max the situation is different, there an index can give you
the answer without scanning all rows. For that the workaround exist in pg.
The pg aggregate functions are very general and no one have special cased
min/max yet. Until that happen the work around works and is fast.

> So, it seems that PG is not soooo well suited for a datawarehouse and/or
> performing extensive statistics/calculations/reportings on large tables,
> is it?

I don't see how you can say that from your example. Just because it uses
an index for the sum above does not mean that it is a lot faster. It still
have to do as many additions as pg has to do.

Sure, mvcc is best when you have both read and writes. But it should still
be comparable in speed even if you only do reads.

--
/Dennis Björklund



В списке pgsql-performance по дате сообщения:

От: "Mohan A"
Дата:
Сообщение: suggestions to improve performace
От: eleven@ludojad.itpp.pl
Дата:
Сообщение: Re: High load average with PostgreSQL 7.4.2 on debian/ibm eserver.