Re: Sequential Scan with LIMIT - Mailing list pgsql-performance

From John Meinel
Subject Re: Sequential Scan with LIMIT
Date
Msg-id 41810FC7.6070501@johnmeinel.com
Whole thread Raw
In response to Re: Sequential Scan with LIMIT  (Jaime Casanova <systemguards@yahoo.com>)
List pgsql-performance
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
=:->

Attachment

pgsql-performance by date:

Previous
From: "Alban Medici (NetCentrex)"
Date:
Subject: Re: Performance Anomalies in 7.4.5
Next
From: "Anjan Dave"
Date:
Subject: Re: Summary: can't handle large number of INSERT/UPDATEs