Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 5510C1337999 for ; Wed, 2 Feb 2011 14:47:41 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 46843-01 for ; Wed, 2 Feb 2011 18:47:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.9]) by mail.postgresql.org (Postfix) with ESMTP id 5A278133616B for ; Wed, 2 Feb 2011 14:47:33 -0400 (AST) Received: from [192.168.1.6] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0MMrpj-1PoIdA01PD-008XyL; Wed, 02 Feb 2011 19:47:24 +0100 Message-ID: <4D49A6B9.4060608@2ndquadrant.com> Date: Wed, 02 Feb 2011 13:47:21 -0500 From: Greg Smith User-Agent: Thunderbird 2.0.0.24 (X11/20100317) MIME-Version: 1.0 To: Mladen Gogala CC: Robert Haas , Andrew Dunstan , Bruce Momjian , Tom Lane , "david@lang.hm" , Craig Ringer , Vitalii Tymchyshyn , "pgsql-performance@postgresql.org" Subject: Re: [HACKERS] Slow count(*) again... References: <201102012247.p11Ml6u02682@momjian.us> <4D48914B.4050403@dunslane.net> <4D489AD1.1010105@vmsinfo.com> <4D499E55.4020107@vmsinfo.com> In-Reply-To: <4D499E55.4020107@vmsinfo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:GqC00BAadwmwmwnU4xA9BAhkYNVfjXgm3W4GrUzmU33 iqltY8UEojPOyZBL+T2UplaisLg8PViOWlFWXD48eH5GGFFgPe F9UXu8vowPfaIi+L4WvYmyjLk6nbMXzgwxTNNu6pbK7n2PZF3E zCXP6AuvEm8cDx7+8Inj8TFRcHq/fbDg+o6WdBhcZAx+Vasbvy K5oG2LG/Jc7V+HELJeWkyRCs+xKxuqoe+WdtWDQW9k= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201102/35 X-Sequence-Number: 42173 Mladen Gogala wrote: > People are complaining about the optimizer not using the indexes all > over the place, there should be a way to > make the optimizer explicitly prefer the indexes, like was the case > with Oracle's venerable RBO (rules based > optimizer). RBO didn't use statistics, it had a rank of access method > and used the access method with the highest > rank of all available access methods. In practice, it translated into: > if an index exists - use it. Given that even Oracle kicked out the RBO a long time ago, I'm not so sure longing for those good old days will go very far. I regularly see queries that were tweaked to always use an index run at 1/10 or less the speed of a sequential scan against the same data. The same people complaining "all over the place" about this topic are also the sort who write them. There are two main fallacies at play here that make this happen: 1) Even if you use an index, PostgreSQL must still retrieve the associated table data to execute the query in order to execute its version of MVCC 2) The sort of random I/O done by index lookups can be as much as 50X as expensive on standard hard drives as sequential, if every block goes to physical hardware. If I were to work on improving this area, it would be executing on some plans a few of us have sketched out for exposing some notion about what indexes are actually in memory to the optimizer. There are more obvious fixes to the specific case of temp tables though. -- Greg Smith 2ndQuadrant US greg@2ndQuadrant.com Baltimore, MD PostgreSQL Training, Services, and 24x7 Support www.2ndQuadrant.us "PostgreSQL 9.0 High Performance": http://www.2ndQuadrant.com/books