X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2FFE29DC986 for ; Tue, 7 Mar 2006 01:04:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82526-08 for ; Tue, 7 Mar 2006 01:04:18 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from linda-2.paradise.net.nz (bm-2a.paradise.net.nz [203.96.152.181]) by postgresql.org (Postfix) with ESMTP id C99E79DC8D7 for ; Tue, 7 Mar 2006 01:04:17 -0400 (AST) Received: from smtp-3.paradise.net.nz (tclsnelb1-src-1.paradise.net.nz [203.96.152.172]) by linda-2.paradise.net.nz (Paradise.net.nz) with ESMTP id <0IVQ005J9RF5UY@linda-2.paradise.net.nz> for pgsql-performance@postgresql.org; Tue, 07 Mar 2006 18:04:17 +1300 (NZDT) Received: from [192.168.1.11] (218-101-29-158.dsl.clear.net.nz [218.101.29.158]) by smtp-3.paradise.net.nz (Postfix) with ESMTP id B15FBE29173; Tue, 07 Mar 2006 18:04:16 +1300 (NZDT) Date: Tue, 07 Mar 2006 18:04:13 +1300 From: Mark Kirkwood Subject: Re: Sequencial scan instead of using index In-reply-to: To: Harry Hehl Cc: pgsql-performance@postgresql.org Message-id: <440D144D.9000106@paradise.net.nz> MIME-version: 1.0 Content-type: text/plain; format=flowed; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051106) References: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.18 required=5 tests=[AWL=0.180] X-Spam-Score: 0.18 X-Spam-Level: X-Archive-Number: 200603/54 X-Sequence-Number: 17491 Harry Hehl wrote: > There seems to be many posts on this issue but I not yet found an answer to the seq scan issue. > > I am having an issue with a joins. I am using 8.0.3 on FC4 > > Query: select * from ommemberrelation where srcobj='somevalue' and dstobj in (select objectid from omfilesysentry where name='dir15_file80'); > > Columns srcobj, dstobj & name are all indexed. > > The planner is over-estimating the number of rows here (33989 vs 100): -> Seq Scan on ommemberrelation (cost=0.00..2394.72 rows=33989 width=177) (actual time=0.078..70.887 rows=100 loops=1) The usual way to attack this is to up the sample size for ANALYZE: ALTER TABLE ommemberrelation ALTER COLUMN srcobj SET STATISTICS 100; ALTER TABLE ommemberrelation ALTER COLUMN dstobj SET STATISTICS 100; -- or even 1000. ANALYZE ommemberrelation; Then try EXPLAIN ANALYZE again. If you can upgrade to 8.1.(3), then the planner can consider paths that use *both* the indexes on srcobj and dstobj (which would probably be the business!). Cheers Mark