Received: from localhost (unknown [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id F15649FB222 for ; Wed, 26 Sep 2007 13:38:20 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 57616-07 for ; Wed, 26 Sep 2007 13:38:12 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 9DF2A9FA5E4 for ; Wed, 26 Sep 2007 13:38:12 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id l8QGc9OZ022792; Wed, 26 Sep 2007 12:38:10 -0400 (EDT) To: pgdba cc: pgsql-performance@postgresql.org Subject: Re: Incorrect row estimates in plan? In-reply-to: <12903194.post@talk.nabble.com> References: <12902068.post@talk.nabble.com> <20944.1190817914@sss.pgh.pa.us> <12903194.post@talk.nabble.com> Comments: In-reply-to pgdba message dated "Wed, 26 Sep 2007 08:24:01 -0700" Date: Wed, 26 Sep 2007 12:38:09 -0400 Message-ID: <22791.1190824689@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/450 X-Sequence-Number: 26995 pgdba writes: > Tom Lane-2 wrote: > -> 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? > 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). Ah. I didn't think you would've put such a specific thing into an index definition, but if you're stuck supporting such badly written queries, maybe there's no other way. I rather doubt that you're going to be able to make this query any faster than it is, short of buying enough RAM to keep the whole table RAM-resident. Pulling 80000 random rows in 1200 msec doesn't sound all that slow to me. The ultimate solution might be to rethink your table designs ... regards, tom lane