pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Harald Lau (Sector-X) <harald@sector-x.de>
To: pgsql-performance@postgresql.org
Subject: no index-usage on aggregate-functions?
Date: Tue, 29 Jun 2004 08:42:14 +0200
Message-ID: <007d01c45da4$3726dcd0$6602a8c0@spock> (raw)

Hi,

I've experienced that PG up to current release does not make use of an index when aggregating. Which of course may result in unacceptable answering times

This behaviour is reproducable on any table with any aggregat function in all of my databases on every machine (PostgreSQL 7.4.2 on i386-redhat-linux-gnu and PostgreSQL 7.2.1 on i686-pc-linux-gnu)

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

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

SELECT Max(date_) AS LatestDate FROM the_table --(index on date_)
=> Seq scan -> takes about 14 sec

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?

Greetings Harald



view thread (8+ messages)  latest in thread

Message-ID: <007d01c45da4$3726dcd0$6602a8c0@spock>
Permalink:  ../007d01c45da4$3726dcd0$6602a8c0@spock/
Also on:    postgresql.org/message-id/007d01c45da4$3726dcd0$6602a8c0@spock

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: harald@sector-x.de
  Subject: Re: no index-usage on aggregate-functions?
  In-Reply-To: <007d01c45da4$3726dcd0$6602a8c0@spock>

* 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