Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id AA94E9FA5AA for ; Wed, 26 Sep 2007 12:24:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 02740-01-4 for ; Wed, 26 Sep 2007 12:24:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by postgresql.org (Postfix) with ESMTP id 2DAB89FA495 for ; Wed, 26 Sep 2007 12:24:04 -0300 (ADT) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1IaYk5-0007Zh-W1 for pgsql-performance@postgresql.org; Wed, 26 Sep 2007 08:24:01 -0700 Message-ID: <12903194.post@talk.nabble.com> Date: Wed, 26 Sep 2007 08:24:01 -0700 (PDT) From: pgdba To: pgsql-performance@postgresql.org Subject: Re: Incorrect row estimates in plan? In-Reply-To: <20944.1190817914@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: postgresql@inbox.com References: <12902068.post@talk.nabble.com> <20944.1190817914@sss.pgh.pa.us> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/449 X-Sequence-Number: 26994 Hi Tom, Tom Lane-2 wrote: > > pgdba writes: >> -> Bitmap Heap Scan on slog (cost=82.98..6434.62 rows=2870 >> width=61) (actual time=50.235..1237.948 rows=83538 loops=1) >> Recheck Cond: ((gid = 10000) AND (rule = ANY >> ('{1,2,8,9,10}'::integer[])) AND (CASE WHEN (rule = ANY >> ('{8,9}'::integer[])) THEN destip ELSE srcip END = >> '192.168.10.23'::inet)) >> -> Bitmap Index Scan on slog_gri_idx >> (cost=0.00..82.26 >> rows=2870 width=0) (actual time=41.306..41.306 rows=83538 loops=1) >> Index Cond: ((gid = 10000) AND (rule = ANY >> ('{1,2,8,9,10}'::integer[])) AND (CASE WHEN (rule = ANY >> ('{8,9}'::integer[])) THEN destip ELSE srcip END = >> '192.168.10.23'::inet)) > > [ blink... ] Pray tell, what is the definition of this index? > > With such a bizarre scan condition, it's unlikely you'll get any really > accurate row estimate. > > regards, tom lane > > Original index: "create index slog_gri_idx on slog (gid,rule,(case when rule in (8,9) then destip else srcip end)) WHERE (rule in (1, 2, 8, 9, 10))" The purpose of that index is to match a specific query (one that gets run frequently and needs to be fast). It is using the destip when rule 8/9, and srcip when other, but only for a subset of the rules (1,2,8,9,10). There are about 18 rules in total, but I'm only interested in those 5. I have tried a couple of indices like: create index test_destip_idx on slog (gid,destip) where rule in (8,9); create index test_srcip_idx on slog (gid,srcip) where rule in (1,2,10); But the original slog_gri_idx index was used instead. Is there a way that I can rewrite that index then? Not that I'm a fan of a CASE statement in a functional index, but I'm at a loss as to how else I can create this. Or what else I can look into to make this faster? -- View this message in context: http://www.nabble.com/Incorrect-row-estimates-in-plan--tf4522692.html#a12903194 Sent from the PostgreSQL - performance mailing list archive at Nabble.com.