Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 7FD2564FD2E for ; Tue, 2 Sep 2008 06:48:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 83004-08 for ; Tue, 2 Sep 2008 06:48:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.cusppoint.com (mail.cusppoint.com [193.120.252.200]) by postgresql.org (Postfix) with ESMTP id 1B8FB64FCDA for ; Tue, 2 Sep 2008 06:48:12 -0300 (ADT) Received: from BREMEN ([194.125.14.201]) by mail.cusppoint.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 2 Sep 2008 10:46:21 +0100 From: "David West" To: References: <1683189597512580954@unknownmsgid> <162867790809010552o624a347aif0eb5fc71e7bbad@mail.gmail.com> <2934211014530751484@unknownmsgid> <162867790809011217n587e6090qdec2c4c6a1f580e6@mail.gmail.com> <48BCB90D.8090606@pws.com.au> <87prnmor13.fsf@mnc.ch> In-Reply-To: <87prnmor13.fsf@mnc.ch> Subject: Re: limit clause breaks query planner? Date: Tue, 2 Sep 2008 10:48:07 +0100 Message-ID: <006901c90ce1$00fa5330$02eef990$@west@cusppoint.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AckM2vzFXwL2y8atR9C/1I2G7iv5qQABD0rA Content-Language: en-ie X-OriginalArrivalTime: 02 Sep 2008 09:46:21.0312 (UTC) FILETIME=[C15DB000:01C90CE0] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.526 tagged_above=0 required=5 tests=MSGID_MULTIPLE_AT=1.211, SARE_MILLIONSOF=0.315 X-Spam-Level: * X-Archive-Number: 200809/29 X-Sequence-Number: 31342 Yes I inserted values in big batches according to a single value of 'B', so indeed a sequence scan may have to scan forward many millions of rows before finding the required value. I have been doing regular analyse commands on my table. I don't think my table is bloated, I haven't been performing updates. However I'm doing a vacuum analyse now and I'll see if that makes any difference. I am using postgres 8.3.1 with a default install on windows - no tweaks to the configuration at all. There are many other columns in my table, but none of them are used in this query. Guillaume in your example you didn't add the limit clause? Postgres chooses the correct index in my case without the limit clause, the problem is with the limit clause. One other difference with your example is both my columns are varchar columns, not integer and text, I don't know if that would make a difference.