Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id EC0479FCA40 for ; Fri, 12 Jan 2007 05:24:04 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 08430-01-7 for ; Fri, 12 Jan 2007 05:23:51 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 2DEB19FC998 for ; Fri, 12 Jan 2007 05:17:54 -0400 (AST) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 087AE73B44; Fri, 12 Jan 2007 09:17:49 +0000 (GMT) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id D70AC27462D; Fri, 12 Jan 2007 09:17:48 +0000 (GMT) Message-ID: <45A7523C.3000007@archonet.com> Date: Fri, 12 Jan 2007 09:17:48 +0000 From: Richard Huxton User-Agent: IceDove 1.5.0.9 (X11/20061220) MIME-Version: 1.0 To: Tobias Brox Cc: Peter Childs , pgsql-performance@postgresql.org Subject: Re: Planner statistics, correlations References: <20070112081631.GA10636@oppetid.no> <20070112090500.GB16243@oppetid.no> In-Reply-To: <20070112090500.GB16243@oppetid.no> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/201 X-Sequence-Number: 22802 Tobias Brox wrote: > [Peter Childs - Fri at 08:56:54AM +0000] >> Can you say what state might be rather than what it is not. I'm guess >> that state is an int but there is only a limited list of possible >> states, if you can say what it might be rather than what it is the >> index is more liklly to be used. > > explain select * from events where state in (1,2,3) and event_time > also estimates almost 5k of rows. Try a partial index: CREATE INDEX my_new_index ON events (event_time) WHERE state in (1,2,3); Now, if that doesn't work you might want to split the query into two... SELECT * FROM events WHERE state IN (1,2,3) AND event_time < '2007-01-01'::date UNION ALL SELECT * FROM events WHERE state IN (1,2,3) AND event_time >= '2007-01-01'::date AND event_time < now(); CREATE INDEX my_new_index ON events (event_time) WHERE state in (1,2,3) AND event_time < '2007-01-01'::date; CREATE INDEX event_time_state_idx ON events (event_time, state); You'll want to replace the index/update the query once a year/month etc. -- Richard Huxton Archonet Ltd