X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 891113A47A3 for ; Thu, 25 Nov 2004 18:44:58 +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 61297-07 for ; Thu, 25 Nov 2004 18:44:56 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 776D23A479C for ; Thu, 25 Nov 2004 18:44:54 +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 iAPIiqJK001248; Thu, 25 Nov 2004 13:44:52 -0500 (EST) To: Dave Steinberg Cc: pgsql-sql@postgresql.org Subject: Re: PG7.4.5: query not using index on date column In-reply-to: <20041123092816.51d7aa5e.dave@redterror.net> References: <20041123092816.51d7aa5e.dave@redterror.net> Comments: In-reply-to Dave Steinberg message dated "Tue, 23 Nov 2004 09:28:16 -0500" Date: Thu, 25 Nov 2004 13:44:51 -0500 Message-ID: <1247.1101408291@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/258 X-Sequence-Number: 19576 Dave Steinberg writes: > -> Seq Scan on messages (cost=0.00..21573.04 rows=436426 width=54) (actual time=5.523..6304.657 rows=462931 loops=1) > Filter: ((received_date >= '2004-11-01'::date) AND (received_date <= '2004-11-30'::date)) How many rows in the table altogether? A rough guess is a few million based on the estimated seqscan cost. That would mean that this query is retrieving about 10% of the table, which is a large enough fraction that the planner will probably think a seqscan is best. It may be right. If you do "set enable_seqscan = off", how does the EXPLAIN ANALYZE output change? If it's not right, you may want to try to adjust random_page_cost and/or effective_cache_size so that the planner's estimated costs are more in line with reality. Beware of making such adjustments on the basis of only one test case, though. regards, tom lane