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 651F39F931D for ; Mon, 8 May 2006 17:40:20 -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 91136-08 for ; Mon, 8 May 2006 17:40:15 -0300 (ADT) X-Greylist: delayed 00:05:03.966177 by SQLgrey- Received: from sccrmhc12.comcast.net (sccrmhc12.comcast.net [204.127.200.82]) by postgresql.org (Postfix) with ESMTP id D7A0B9F931E for ; Mon, 8 May 2006 17:40:12 -0300 (ADT) Received: from [192.168.1.52] (c-65-96-235-5.hsd1.ma.comcast.net[65.96.235.5]) by comcast.net (sccrmhc12) with ESMTP id <200605082033460120056scpe>; Mon, 8 May 2006 20:33:47 +0000 Message-ID: <445FAB2A.9050401@comcast.net> Date: Mon, 08 May 2006 16:33:46 -0400 From: Jeffrey Tenny User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: Tom Lane CC: "Jim C. Nasby" , pgsql-performance@postgresql.org Subject: Re: performance question (something to do w/ parameterized References: <445F7FF8.6070707@comcast.net> <20060508173812.GW99570@pervasive.com> <445F9F6B.9040200@comcast.net> <29345.1147118920@sss.pgh.pa.us> In-Reply-To: <29345.1147118920@sss.pgh.pa.us> 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: 200605/155 X-Sequence-Number: 18942 The original set of indexes were: Indexes: "x_c_idx" btree (c) "x_f_idx" btree (f) "testindex2" btree (f, c) I dropped the multicolumn index 'testindex2', and a new explain analyze looks like this: Sort (cost=35730.71..35768.28 rows=1503 width=16) (actual time=962.555..964.467 rows=677 loops=1) Sort Key: f, c -> Seq Scan on x (cost=0.00..34937.60 rows=1503 width=16) (actual time=5.449..956.594 rows=677 loops=1) Filter: ((f = 1) OR (f = 2) OR (f = 3) ... Turning on the server debugging again, I got roughly identical query times with and without the two column index. It appears to have ignored the other indexes completely. Tom Lane wrote: > 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 >