Re: timestamped archive data index searches

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Stephen Birch <sgbirch(at)hotmail(dot)com>
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, pgsql-general(at)postgreSQL(dot)org
Subject: Re: timestamped archive data index searches
Date: 2002-07-21 11:41:03
Message-ID: 20020721114103.GA6647@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, Jul 21, 2002 at 07:32:22 +0000,
Stephen Birch <sgbirch(at)hotmail(dot)com> wrote:
> I am still puzzled by the systems use of sequence scans. Using Tom's
> suggestion, I am now able to get a reasonable response time on the 1M
> record database by searching on the tstamp field.
>
> But ... I tried asking the database what the earliest record is:
>
> SELECT MIN(tstamp) FROM det;
>
> This used a sequence scan even if I do a SET ENABLE_SEQSCAN to off.
>
> Shouldn't this also use an index?

No because there isn't hardcoded special knowledge about the min and max
aggregate functions. This gets discussed on the lists pretty often so
you should be able to find more detailed discussions in the archives.
If there is a usable index on column of interest you should rewrite
your query to use order by and limit. For example:
select tstamp from det order by tstamp limit 1;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Masaru Sugawara 2002-07-21 12:49:04 Re: Oracle to PGSQL -- need help
Previous Message Pankaj Naug 2002-07-21 09:55:22