Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id A545D64FCF3 for ; Tue, 2 Sep 2008 18:00:57 -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 11056-02 for ; Tue, 2 Sep 2008 18:00:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C411B64FCEA for ; Tue, 2 Sep 2008 18:00:52 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m82L0mZb005926; Tue, 2 Sep 2008 17:00:48 -0400 (EDT) To: "Matt Smiley" cc: david.west@cusppoint.com, pgsql-performance@postgresql.org Subject: Re: limit clause breaks query planner? In-reply-to: <48BD33B2.D078.0028.0@rentrak.com> References: <48BD33B2.D078.0028.0@rentrak.com> Comments: In-reply-to "Matt Smiley" message dated "Tue, 02 Sep 2008 12:38:19 -0700" Date: Tue, 02 Sep 2008 17:00:48 -0400 Message-ID: <5925.1220389248@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200809/42 X-Sequence-Number: 31355 "Matt Smiley" writes: > So an Index Scan is always going to have a higher cost estimate than > an equivalent Seq Scan returning the same result rows (unless > random_page_cost is < 1). That's why I think the planner is always > preferring the plan that uses a Seq Scan. If that were the case, we'd never choose an indexscan at all... It's true that a plain indexscan is not preferred for queries that will return a large fraction of the table. However, it should be willing to use a bitmap scan for this query, given default cost settings (the default cost settings will cause it to prefer bitmap scan for retrieving up to about a third of the table, in my experience). I too am confused about why it doesn't prefer that choice in the OP's example. It would be interesting to alter the random_page_cost setting and see if he gets different results. regards, tom lane