Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id E6799B5DBC1 for ; Fri, 17 Jun 2011 09:43:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 48294-09 for ; Fri, 17 Jun 2011 12:43:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp.peak6.com (smtp.peak6.com [38.98.137.6]) by mail.postgresql.org (Postfix) with ESMTP id 3F1EEB5DBC2 for ; Fri, 17 Jun 2011 09:43:48 -0300 (ADT) X-AuditID: 0a64cb1e-b7bf7ae000000b0d-3d-4dfb4c020008 Message-ID: <4DFB4C02.3020505@peak6.com> Date: Fri, 17 Jun 2011 07:43:46 -0500 From: Shaun Thomas Reply-To: Organization: Peak6 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101210 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: Svetlin Manavski CC: Magnus Hagander , Subject: Re: seq scan in the case of max() on the primary key column References: <4DFA4D2F.8020101@peak6.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed content-transfer-encoding: 7bit X-Originating-IP: [10.10.221.50] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHIsWRmVeSWpSXmKPExsXCxcQrpsvs89vX4Ns1dosVn+6wWlyfeY7Z Yu7ds0wOzB47Z91l99jUdpzZ48K+aewBzFENjDaJeXn5JYklqQopqcXJtkoBro7eZgrBJYl5 KYlFKQoumcXJOYmZualFSgqZKbZKRkoKBTmJyam5qXkltkqJBQWpeSlKdlwKGMAGqCwzTyE1 Lzk/JTMv3VbJM9hf18LC1FLXUMkuHgES2lgyDt2fwFLwiL2idd9LxgbGXrYuRk4OCQETiccT NrJA2GISF+6tB4vzCmhI7L78gBnEZhFQlbj3rQeshk1ATWLh7puMILaQgKzE/lXnWEFsfgFh iX0fmsDqRQUKJb4dvcUMMUdQ4uTMJ2C9IgKGEvNuXgDrZRbwldj26wtYr7CAn8TV841A9VxA M48zSlxZfgnI4eDgFHCUmP4xCqLeVuLCnOssELa8xPa3c5ghbpCTuNPwnA2kXEJAQeLeX6cJ jEKzkGyehaR7FpLuBYzMqxjFi8sSkzMyTQuKc0sKDPUKUhOzzfTyUks2MYJiOeW03A7G6UsV DzEKcDAq8fBuCPrlK8SaWFZcmXuIUYKDWUmE97zZb18h3pTEyqrUovz4otKc1OJDjNrAIJvI LMWdnA9MM3kl8cYGBkrivF9c3/oKCaQD00B2ampBahFMNRMHp1QDI/MPxxlL+hZsrXg4a2Px tK+Ovf+/Gu5xWdlms+vx3EUaQu/vdkYEZ1sJeGXmzzwl/LzAIbjSZO3yqiT3JZaKcVmeSW7e +n+VriwX71rooTbxxf8ItWjO7R8be88smHSI4cZSNtEF1knbF+vMVfdyyOo2ZP1RqLNHZpX6 i+6NXspGSrv+3ikzUWIpzkg01GIuKk4EAHNZpu3xAgAA X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/153 X-Sequence-Number: 44086 On 06/17/2011 06:22 AM, Svetlin Manavski wrote: > Shaun, that solution is brilliant. Don't thank me. I actually got the basic idea from a post here a couple years ago. The only difference is I formalized it somewhat and put it in our utility schema, where I put lots of other random useful stored procs I've accumulated over the years. I have another one that works with dates. :) I assume you already modified it by removing the 'utility' schema prefix from the recursive call. The recursive call is in case the child tables are themselves used as a template for further inheritance. It's rare, but possible. This function will always get you the max value on a column in a series of partitioned tables, and quickly so long as it's indexed. It's a bit of a hack, but it's worked fine for us while we wait for the planner to catch up. :) -- Shaun Thomas OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@peak6.com ______________________________________________ See http://www.peak6.com/email_disclaimer.php for terms and conditions related to this email