From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: Harald Lau (Sector-X) <harald@sector-x.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: no index-usage on aggregate-functions?
Date: Tue, 29 Jun 2004 15:36:16 +0800
Message-ID: <40E11BF0.3020109@familyhealth.com.au> (raw)
In-Reply-To: <007d01c45da4$3726dcd0$6602a8c0@spock>
References: <007d01c45da4$3726dcd0$6602a8c0@spock>
> f.e. querying against a 2.8-mio-records (2.800.000) table the_table
> SELECT count(*) FROM the_table
> => Seq scan -> takes about 12 sec
This cannot be made O(1) in postgres due to MVCC. You just have to live
with it.
> SELECT Avg(num_found) AS NumFound FROM the_table --(index on num_found)
> => Seq scan -> takes about 10 sec
>
> SELECT Sum(num_found) AS TotalFound FROM the_table --(index on num_found)
> => Seq scan -> takes about 11 sec
Average and sum can never use an index AFAIK, in any db server. You
need information from every row.
> SELECT Max(date_) AS LatestDate FROM the_table --(index on date_)
> => Seq scan -> takes about 14 sec
Yep, that's due to postgresql's type extensibility. You should use th
workaround you point out below.
> But
> SELECT date_ AS LatestDate FROM the_table ORDER BY date_ DESC LIMIT 1;
> => Index scan -> takes 0.18 msec
>
> MS SQLServer 2000: Use of an appropriate index _whenever_ aggregating.
>
> Am I doing something wrong?
Nope.
Chris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: chriskl@familyhealth.com.au, harald@sector-x.de
Subject: Re: no index-usage on aggregate-functions?
In-Reply-To: <40E11BF0.3020109@familyhealth.com.au>
References: <007d01c45da4$3726dcd0$6602a8c0@spock> <40E11BF0.3020109@familyhealth.com.au>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox