Skip site navigation (1) Skip section navigation (2)

Re: "select max/count(id)" not using index

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Ryszard Lach <siaco(at)autograf(dot)pl>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: "select max/count(id)" not using index
Date: 2003-12-22 11:03:45
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
Dnia 2003-12-22 11:39, Użytkownik Ryszard Lach napisał:

> Hi.
> 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):
'select count(id)'
Yes, this is normal. Because of MVCC all rows must be checked and 
Postgres doesn't cache count(*) like Mysql.

'select max(id)'
This is also normal, but try to change this query into:
select id from some_table order by id desc limit 1;

What is your Postgresql version?

Tomasz Myrta

In response to

pgsql-performance by date

Next:From: Michael GuerinDate: 2003-12-22 19:11:54
Subject: postgresql performance on linux port
Previous:From: Pavel StehuleDate: 2003-12-22 11:03:05
Subject: Re: "select max/count(id)" not using index

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group