From: Michael McFarland <sidlonDoesntLikeSpam@yahoo.com>
To: pgsql-performance@postgresql.org
Subject: adding 'limit' leads to very slow query
Date: Mon, 07 Mar 2005 18:39:43 -0500
Message-ID: <opsnaj0hctsvs6tg@localhost.localdomain> (raw)
I'm trying to understand why a particular query is slow, and it seems
like the optimizer is choosing a strange plan. See this summary:
* I have a large table, with an index on the primary key 'id' and on a
field 'foo'.
> select count(*) from foo;
1,000,000
> select count(*) from foo where bar = 41;
7
* This query happens very quickly.
> explain select * from foo where barId = 412 order by id desc;
Sort ()
Sort key= id
-> Index scan using bar_index on foo ()
Index cond: barId = 412
But this query takes forever
> explain select * from foo where barId = 412 order by id desc limit 25;
Limit ()
-> Index scan backward using primarykey_index
Filter: barID = 412
Could anyone shed some light on what might be happening here?
- Michael
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
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: sidlonDoesntLikeSpam@yahoo.com
Subject: Re: adding 'limit' leads to very slow query
In-Reply-To: <opsnaj0hctsvs6tg@localhost.localdomain>
* 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