pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomasz Myrta <jasiek@klaster.net>
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 12:03:45 +0100
Message-ID: <3FE6CF91.6070300@klaster.net> (raw)
In-Reply-To: <20031222103918.GA23673@siaco.id.pl>
References: <20031222103918.GA23673@siaco.id.pl>

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?

Regards,
Tomasz Myrta




view thread (5+ messages)

Message-ID: <3FE6CF91.6070300@klaster.net>
Permalink:  ../3FE6CF91.6070300@klaster.net/
Also on:    postgresql.org/message-id/3FE6CF91.6070300@klaster.net

 · 

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: jasiek@klaster.net, siaco@autograf.pl
  Subject: Re: "select max/count(id)" not using index
  In-Reply-To: <3FE6CF91.6070300@klaster.net>

* 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