X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 09C589F931D for ; Mon, 8 May 2006 17:09:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 82900-09 for ; Mon, 8 May 2006 17:08:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 5A0359F931E for ; Mon, 8 May 2006 17:08:55 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k48K8e6f029346; Mon, 8 May 2006 16:08:40 -0400 (EDT) To: Jeffrey Tenny cc: "Jim C. Nasby" , pgsql-performance@postgresql.org Subject: Re: performance question (something to do w/ parameterized In-reply-to: <445F9F6B.9040200@comcast.net> References: <445F7FF8.6070707@comcast.net> <20060508173812.GW99570@pervasive.com> <445F9F6B.9040200@comcast.net> Comments: In-reply-to Jeffrey Tenny message dated "Mon, 08 May 2006 15:43:39 -0400" Date: Mon, 08 May 2006 16:08:40 -0400 Message-ID: <29345.1147118920@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/154 X-Sequence-Number: 18941 Jeffrey Tenny writes: > Well, since I don't know the exact parameter values, just substituting > 1-650 for $1-$650, I get: > Index Scan using testindex2 on x (cost=0.00..34964.52 rows=1503 > width=16) (actual time=0.201..968.252 rows=677 loops=1) > Filter: ((f = 1) OR (f = 2) OR (f = 3) OR (f = 4) ... > So index usage is presumably good on this one. No, that's not a very nice plan at all --- the key thing to notice is it says Filter: not Index Cond:. What you've actually got here is a full-index scan over testindex2 (I guess it's doing that to achieve the requested sort order), then computation of a 650-way boolean OR expression for each row of the table. Ugh. The other way of doing this would involve 650 separate index probes and then sorting the result. Which would be pretty expensive too, but just counting on my fingers it seems like that ought to come out at less than the 35000 cost units for this plan. The planner evidently is coming up with a different answer though. You might try dropping testindex2 (which I suppose is an index on (f,c)) so that it has only an index on f to play with, and see what plan it picks and what the estimated/actual costs are. regards, tom lane