X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4F20E3A4915 for ; Thu, 28 Oct 2004 16:27:22 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 33533-01 for ; Thu, 28 Oct 2004 15:27:20 +0000 (GMT) Received: from ct.radiology.uiowa.edu (ct.radiology.uiowa.edu [129.255.60.186]) by svr1.postgresql.org (Postfix) with ESMTP id 4F4363A490E for ; Thu, 28 Oct 2004 16:27:19 +0100 (BST) Received: from [192.168.1.11] (12-217-241-0.client.mchsi.com [12.217.241.0]) by ct.radiology.uiowa.edu (8.11.6/8.11.6) with ESMTP id i9SFRF303897; Thu, 28 Oct 2004 10:27:16 -0500 Message-ID: <41810FC7.6070501@johnmeinel.com> Date: Thu, 28 Oct 2004 10:27:03 -0500 From: John Meinel User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jaime Casanova Cc: pgsql-performance@postgresql.org Subject: Re: Sequential Scan with LIMIT References: <20041027171621.60824.qmail@web50006.mail.yahoo.com> In-Reply-To: <20041027171621.60824.qmail@web50006.mail.yahoo.com> X-Enigmail-Version: 0.86.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig17E31C0633DD7D3107A1AF65" X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/459 X-Sequence-Number: 8935 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig17E31C0633DD7D3107A1AF65 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 =:-> --------------enig17E31C0633DD7D3107A1AF65 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (Cygwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFBgQ/OJdeBCYSNAAMRApqrAJ4p9MtARog1Loz4zx2h+cRZ1iTGhQCfQeSu pbf0rEN1a+c6NUF72t/7xyE= =RcJj -----END PGP SIGNATURE----- --------------enig17E31C0633DD7D3107A1AF65--