From: John Meinel <john@johnmeinel.com>
To: Jaime Casanova <systemguards@yahoo.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Sequential Scan with LIMIT
Date: Thu, 28 Oct 2004 10:27:03 -0500
Message-ID: <41810FC7.6070501@johnmeinel.com> (raw)
In-Reply-To: <20041027171621.60824.qmail@web50006.mail.yahoo.com>
References: <20041027171621.60824.qmail@web50006.mail.yahoo.com>
Jaime Casanova wrote:
[...]
>
> In http://www.postgresql.org/docs/faqs/FAQ.html under
> "4.8) My queries are slow or don't make use of the
> indexes. Why?" says:
>
> "However, LIMIT combined with ORDER BY often will use
> an index because only a small portion of the table is
> returned. In fact, though MAX() and MIN() don't use
> indexes, it is possible to retrieve such values using
> an index with ORDER BY and LIMIT:
> SELECT col
> FROM tab
> ORDER BY col [ DESC ]
> LIMIT 1;"
>
> So, maybe you can try your query as
>
> SELECT col FROM mytable
> WHERE col = 'myval'
> ORDER BY col
> LIMIT 1;
>
> regards,
> Jaime Casanova
Thanks for the heads up. This actually worked. All queries against that
table have turned into index scans instead of sequential.
John
=:->
Attachments:
signature.asc (application/pgp-signature, 252B) download
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: john@johnmeinel.com, systemguards@yahoo.com
Subject: Re: Sequential Scan with LIMIT
In-Reply-To: <41810FC7.6070501@johnmeinel.com>
* 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