Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id A6E2C9FA35C for ; Fri, 12 Jan 2007 05:57:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 44900-06 for ; Fri, 12 Jan 2007 05:56:53 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from lynet.oppetid.no (oppetid.no [80.65.51.2]) by postgresql.org (Postfix) with ESMTP id DAEBA9FB25E for ; Fri, 12 Jan 2007 05:56:56 -0400 (AST) Received: by lynet.oppetid.no (Postfix, from userid 1019) id 5491E11AF95; Fri, 12 Jan 2007 10:56:55 +0100 (CET) Date: Fri, 12 Jan 2007 10:56:55 +0100 From: Tobias Brox To: Richard Huxton Cc: Tobias Brox , Peter Childs , pgsql-performance@postgresql.org Subject: Re: Planner statistics, correlations Message-ID: <20070112095655.GA5128@oppetid.no> References: <20070112081631.GA10636@oppetid.no> <20070112090500.GB16243@oppetid.no> <45A7523C.3000007@archonet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <45A7523C.3000007@archonet.com> Organization: Group Nordicbet User-Agent: Mutt/1.5.9i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/202 X-Sequence-Number: 22803 [Richard Huxton - Fri at 09:17:48AM +0000] > Try a partial index: > CREATE INDEX my_new_index ON events (event_time) > WHERE state in (1,2,3); I have that, the index is used and the query is lightning fast - the only problem is that the planner is using the wrong estimates. This becomes a real problem when doing joins and more complex queries. > Now, if that doesn't work you might want to split the query into two... Hm, that's an idea - to use a two-pass query ... first: select max(event_time) from events where state in (1,2,3); and then use the result: select * from events where event_time>? and event_time