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 E1D7C3CCE8B for ; Fri, 17 Dec 2004 18:25:05 +0000 (GMT) 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 01986-03 for ; Fri, 17 Dec 2004 18:25:01 +0000 (GMT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by svr1.postgresql.org (Postfix) with ESMTP id 3FBCD3CC9B9 for ; Fri, 17 Dec 2004 18:24:59 +0000 (GMT) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1CfMmH-0006wU-00; Fri, 17 Dec 2004 13:24:33 -0500 To: Tom Lane Cc: Greg Stark , Richard Huxton , David Brown , pgsql-performance@postgresql.org Subject: Re: Seqscan rather than Index References: <20041217011853.9E8FF3CADB0@svr1.postgresql.org> <41C2D936.3060901@archonet.com> <87acsdkjte.fsf@stark.xeocode.com> <21110.1103305481@sss.pgh.pa.us> In-Reply-To: <21110.1103305481@sss.pgh.pa.us> From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 17 Dec 2004 13:24:33 -0500 Message-ID: <87zn0cixzy.fsf@stark.xeocode.com> Lines: 38 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.049 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200412/217 X-Sequence-Number: 9592 Tom Lane writes: > Greg Stark writes: > > Postgres is also more pessimistic about the efficiency of index scans. It's > > willing to use a sequential scan down to well below 5% selectivity when other > > databases use the more traditional rule of thumb of 10%. > > However, other databases are probably basing their analysis on a > different execution model. Since we have to visit both heap and index > in all cases, we do indeed have a larger penalty for index use. It's only in special cases that other databases do not have to look at the heap. For simple queries like "select * from x where foo > ?" they still have to look at the heap. I never looked into how much of a bonus Oracle gives for the index-only case, I'm not sure it even takes it into account. > I've looked pretty closely at the cost model for index access, believe me. > It's not pessimistic; if anything it is undercharging for index access. I think there's another effect here beyond the physical arithmetic. There's a kind of teleological reasoning that goes something like "If the user created the index chances are it's because he wanted it to be used". I guess that argues more for more aggressive selectivity estimates than for biased index costing though. If I'm doing "where foo > ?" then if there's an index on foo I probably put it there for a reason and want it to be used even if postgres doesn't really have a clue how selective the query will be. > I think the one effect that's not being modeled is amortization of index > fetches across successive queries. And across multiple fetches in a single query, such as with a nested loop. It seems like the effective_cache_size parameter should be having some influence here. -- greg