Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id DFE561337B93 for ; Wed, 30 Mar 2011 15:51:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 98357-10 for ; Wed, 30 Mar 2011 18:51:28 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 3E9691337999 for ; Wed, 30 Mar 2011 15:51:27 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Wed, 30 Mar 2011 13:51:26 -0500 Message-Id: <4D93355C020000250003BFAA@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Wed, 30 Mar 2011 13:51:24 -0500 From: "Kevin Grittner" To: "pgsql-bugs@postgresql.org" , "Lawrence Cohan" Subject: Re: Postgres not using indexes References: <965AA5440EAC094E9F722519E285ACEDAC5E66A53D@WWCEXCHANGE.web.web.com> <4D9317D3020000250003BF7B@gw.wicourts.gov> <965AA5440EAC094E9F722519E285ACEDAC5E66A556@WWCEXCHANGE.web.web.com> <4D9322E8020000250003BF8C@gw.wicourts.gov> <965AA5440EAC094E9F722519E285ACEDAC5E66A55F@WWCEXCHANGE.web.web.com> In-Reply-To: <965AA5440EAC094E9F722519E285ACEDAC5E66A55F@WWCEXCHANGE.web.web.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201103/394 X-Sequence-Number: 29904 Lawrence Cohan wrote: > Please see updated attachment that includes the tables involved in > the simple query below and all their indexes. Well, that rules out a couple common problems (comparisons between different types and incorrect indexing). > We believe that the performance issue is due to the query not > using any index but doing seq scans instead So it appears. > and this is very little related to the knowledge from the link you > posted below. Oh, but it is very much related. The PostgreSQL optimizer looks at all the various plans available, calculates a cost for each, and run the one with the lowest calculated cost. Various configuration parameters affect the costing calculations, and thus the plan ultimately chosen. To get good plans, the configuration must accurately model the actual costs for your particular machine. Having seen that the types match and the indexes look usable, it must come down to something in your configuration. Probably the easiest way to show that is to run the query here and post the results: http://wiki.postgresql.org/wiki/Server_Configuration > As you can see we picked a simple query with INNER JOIN between > two indexed tables where postgres 8.3 and 9.0 decides to not use > existing indexes for whatever reason. The reason is that with the configuration you're using, PostgreSQL calculates the cost of using the index as being higher than the cost of a sequential scan. The trick is to find where your configuration is wrong, so that the calculated costs better match the reality on your server. -Kevin