X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E73A0DB621 for ; Tue, 1 Nov 2005 21:08:05 -0400 (AST) 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 78954-07 for ; Wed, 2 Nov 2005 01:08:02 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 36E6ADB5D2 for ; Tue, 1 Nov 2005 21:08:03 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id jA21834O013299 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 1 Nov 2005 18:08:05 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id jA2183WJ089038; Tue, 1 Nov 2005 18:08:03 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jA2182c4089037; Tue, 1 Nov 2005 18:08:02 -0700 (MST) (envelope-from mfuhr) Date: Tue, 1 Nov 2005 18:08:02 -0700 From: Michael Fuhr To: David Durham Cc: pgsql-sql@postgresql.org Subject: Re: Index lookup on > and < criteria Message-ID: <20051102010802.GA88950@winnie.fuhr.org> References: <4367B16B.2050003@vailsys.com> <20051101192123.GA86877@winnie.fuhr.org> <4367DC51.8090803@vailsys.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4367DC51.8090803@vailsys.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.006 required=5 tests=[AWL=0.006] X-Spam-Score: 0.006 X-Spam-Level: X-Archive-Number: 200511/17 X-Sequence-Number: 23269 On Tue, Nov 01, 2005 at 03:21:21PM -0600, David Durham wrote: > sipcdr=# explain analyze select * from october_cdr_call where begin_time > >= '10/1/2005' and begin_time < '10/4/2005'; > > QUERY PLAN > > -------------------------------------------------------------------------------- > -------------------------------------------------------------------------- > Index Scan using october_begin_time on october_cdr_call > (cost=0.00..98383.82 r > ows=24594 width=568) (actual time=0.280..79274.579 rows=538592 loops=1) > Index Cond: ((begin_time >= '2005-10-01 00:00:00'::timestamp without > time zon > e) AND (begin_time < '2005-10-04 00:00:00'::timestamp without time zone)) > Total runtime: 81457.938 ms > (3 rows) The estimated row count (24594) is much different than the actual row count (538592), which makes me wonder if the statistics are up to date. Try running ANALYZE on the table and then see if the estimate is more accurate. With a more accurate estimate the planner might choose a sequential scan, but the other queries you posted suggest that a sequential scan is indeed faster when you're fetching this much data. > >Has the table been vacuumed and analyzed? > > Brand new table that I haven't deleted anything from yet. The table should still be analyzed to update the planner's statistics. The planner uses statistics to estimate how many rows a query will return, and that influences the choice of plan. > >How much memory do you have and what's your effective_cache_size > >setting? > > 1.5 gig RAM, effective_cache_size is the default, so 1000. You'd probably benefit from raising effective_cache_size to reflect the amount of memory being used for disk cache, both by PostgreSQL and by the operating system; you might also benefit from adjusting other settings like shared_buffers. See a tuning guide like the following for advice: http://www.powerpostgresql.com/PerfList -- Michael Fuhr