Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 9849CB5DBC0 for ; Fri, 17 Jun 2011 15:00:10 -0300 (ADT) 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 32162-05 for ; Fri, 17 Jun 2011 18:00:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.17.10]) by mail.postgresql.org (Postfix) with ESMTP id ED682B5D801 for ; Fri, 17 Jun 2011 15:00:03 -0300 (ADT) Received: from [192.168.1.7] (mail.highperformancepostgresql.com [71.179.240.8]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0MErUc-1QHhxj2gyQ-00GSLh; Fri, 17 Jun 2011 20:00:02 +0200 Message-ID: <4DFB9620.8030702@2ndQuadrant.com> Date: Fri, 17 Jun 2011 14:00:00 -0400 From: Greg Smith User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.16) Gecko/20110505 Icedove/3.0.11 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: seq scan in the case of max() on the primary key column References: <4DFA4D2F.8020101@peak6.com> <4DFB4C02.3020505@peak6.com> In-Reply-To: <4DFB4C02.3020505@peak6.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:uav6E20uFgz+REx/qJxfZfp8C1Qwd4ZAtImnEFXXTSr 1e4ct7I9RFZZviFJJY01Qy1vLXpyDmaS4itZpcUotMFP+2ucUh ZvOt7BhGlSN2W0ltbWSBEseeJH2eDm3yiN1+4fycE/ZM+09tJw j0hyZVIUOu8DVwsyOT9nYnRRVfe8gQeoWx2v5xPr4BFX2gs4eu R3xWKhmF9ZCY2WnajRfAZn464r0wxiwDxuW7X6s2Zc= 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: 201106/159 X-Sequence-Number: 44092 On 06/17/2011 08:43 AM, Shaun Thomas wrote: > It's a bit of a hack, but it's worked fine for us while we wait for > the planner to catch up. :) Right. In situations where people can modify their application to redirect MIN/MAX() calls over to directly query the individual partitions, that's a great workaround. Your function is the slickest such solution I've seen for that, so filing it away in case this pops up in that situation. But if you can't touch the application code and just need it to work as desired, you either need to use PostgreSQL 9.1 (not yet released) or figure out how to backport that fix into an earlier version (not easy). A babbled a bit about this specific case at http://blog.2ndquadrant.com/en/2011/06/max-partitioning-with-min-pain.html if anyone wants more information, or a specific simple test case to play with. -- 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