Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6vkP-0003GK-AS for pgsql-performance@arkaria.postgresql.org; Wed, 07 Aug 2013 04:53:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V6vkO-00025X-3p for pgsql-performance@arkaria.postgresql.org; Wed, 07 Aug 2013 04:53:20 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6vkM-00025Q-Ud for pgsql-performance@postgresql.org; Wed, 07 Aug 2013 04:53:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6vkG-0002ok-T6 for pgsql-performance@postgresql.org; Wed, 07 Aug 2013 04:53:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id r774qwEe003620; Wed, 7 Aug 2013 00:52:59 -0400 From: Tom Lane To: Claudio Freire cc: Mark Kirkwood , Ivan Voras , Michael Paquier , postgres performance list Subject: Re: ORDER BY, LIMIT and indexes In-reply-to: References: <52017F1F.7020700@catalyst.net.nz> Comments: In-reply-to Claudio Freire message dated "Tue, 06 Aug 2013 20:09:57 -0300" Date: Wed, 07 Aug 2013 00:52:58 -0400 Message-ID: <3619.1375851178@sss.pgh.pa.us> X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Claudio Freire writes: > Alternatively, a token startup cost could be added to those kinds of > filtered sequential scans, when the filtering term is selective > enough. That would offset the cost just a little bit, but enough to > favor index over sequential on the right cases. Maybe not so "token". Really, if there's a filter condition having a selectivity of say 1/N, we should expect to have to skip over O(N) tuples before finding a match. (Not sure at this late hour if the expectation is N, or N/2, or something else ... but anyway it's in that ballpark.) We don't take that into account in computing the startup time of a plan node, but I'm thinking we should. In this particular example, that would penalize the seqscan plan and not the indexscan plan, because in the indexscan case the condition is being applied by the index; it's not an after-the-fact filter. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance