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 193043A1D8A for ; Sat, 20 Nov 2004 05:20:02 +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 28242-10 for ; Sat, 20 Nov 2004 05:19:51 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7EE0D3A49DA for ; Sat, 20 Nov 2004 05:19:50 +0000 (GMT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id iAK5JkXK016680; Sat, 20 Nov 2004 00:19:46 -0500 (EST) To: sarlav kumar Cc: pgsql-performance@postgresql.org Subject: Re: help needed -- sequential scan problem In-reply-to: <20041119223122.49470.qmail@web51301.mail.yahoo.com> References: <20041119223122.49470.qmail@web51301.mail.yahoo.com> Comments: In-reply-to sarlav kumar message dated "Fri, 19 Nov 2004 14:31:22 -0800" Date: Sat, 20 Nov 2004 00:19:46 -0500 Message-ID: <16679.1100927986@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200411/316 X-Sequence-Number: 9270 sarlav kumar writes: > I have a query which does not use index scan unless I force postgres to use index scan. I dont want to force postgres, unless there is no way of optimizing this query. The major issue seems to be in the sub-selects: > -> Seq Scan on merchant_purchase mp (cost=0.00..95.39 rows=44 width=4) (actual time=2.37..2.58 rows=6 loops=619) > Filter: (merchant_id = $0) where the estimated row count is a factor of 7 too high. If the estimated row count were even a little lower, it'd probably have gone for an indexscan. You might get some results from increasing the statistics target for merchant_purchase.merchant_id. If that doesn't help, I'd think about reducing random_page_cost a little bit. regards, tom lane