Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id DD28B9F9CB4 for ; Wed, 15 Aug 2007 17:00:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 66867-05 for ; Wed, 15 Aug 2007 17:00:39 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from lists.commandprompt.com (host-254.commandprompt.net [207.173.203.254]) by postgresql.org (Postfix) with ESMTP id 844489F98E1 for ; Wed, 15 Aug 2007 17:00:43 -0300 (ADT) Received: from perhan.alvh.no-ip.org (201-221-221-172.bk12-dsl.surnet.cl [201.221.221.172]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id l7FK0hWd003029; Wed, 15 Aug 2007 13:00:45 -0700 Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 046FC47C55; Wed, 15 Aug 2007 16:00:40 -0400 (CLT) Date: Wed, 15 Aug 2007 16:00:39 -0400 From: Alvaro Herrera To: =?iso-8859-1?Q?Sebasti=E1n?= Baioni Cc: Performance PostgreSQL Subject: Re: Indexscan is only used if we use "limit n" Message-ID: <20070815200039.GF25596@alvh.no-ip.org> References: <377451.48008.qm@web36104.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <377451.48008.qm@web36104.mail.mud.yahoo.com> User-Agent: Mutt/1.5.16 (2007-06-11) X-Virus-Scanned: ClamAV 0.91.1/3962/Wed Aug 15 00:21:42 2007 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Wed, 15 Aug 2007 13:00:45 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/153 X-Sequence-Number: 26283 Sebastián Baioni escribió: > Hello, > Whe are running PostgreSQL 8.2.0 on amd64-portbld-freebsd6.2, compiled by GCC cc (GCC) 3.4.6 [FreeBSD] 20060305. > The query only uses the index if we have a "limit n": > Without "Limit n" > explain > select esapcuit, esapcuil > from esact00 t1 > order by esapcuit, esapcuil > > Sort (cost=843833.82..853396.76 rows=3825177 width=30) > Sort Key: esapcuit, esapcuil > -> Seq Scan on esact00 t1 (cost=0.00..111813.77 rows=3825177 width=30) That's right. What else did you expect? It estimates it has to return 3 million rows after all -- using an indexscan would be slow. -- Alvaro Herrera http://www.amazon.com/gp/registry/DXLWNGRJD34J "Puedes vivir solo una vez, pero si lo haces bien, una vez es suficiente"