pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: Ryszard Lach <siaco@autograf.pl>
Cc: pgsql-performance@postgresql.org
Subject: Re: "select max/count(id)" not using index
Date: Mon, 22 Dec 2003 18:56:50 +0800
Message-ID: <3FE6CDF2.10608@familyhealth.com.au> (raw)
In-Reply-To: <20031222103918.GA23673@siaco.id.pl>
References: <20031222103918.GA23673@siaco.id.pl>


> I have a table with 24k records and btree index on column 'id'. Is this
> normal, that 'select max(id)' or 'select count(id)' causes a sequential
> scan? It takes over 24 seconds (on a pretty fast machine):
> 
> => explain ANALYZE select max(id) from ogloszenia;

Yes, it is.  It is a known issue with Postgres's extensible operator 
architecture.

The work around is to have an index on the id column and do this instead:

SELECT id FROM ogloszenia ORDER BY id DESC LIMIT 1;

Which will be really fast.

Chris




view thread (5+ messages)  latest in thread

Message-ID: <3FE6CDF2.10608@familyhealth.com.au>
Permalink:  ../3FE6CDF2.10608@familyhealth.com.au/
Also on:    postgresql.org/message-id/3FE6CDF2.10608@familyhealth.com.au

 · 

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: chriskl@familyhealth.com.au, siaco@autograf.pl
  Subject: Re: "select max/count(id)" not using index
  In-Reply-To: <3FE6CDF2.10608@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