Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id CCB0F2E01ED for ; Thu, 13 Mar 2008 03:35:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 41625-06 for ; Thu, 13 Mar 2008 03:35:12 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by postgresql.org (Postfix) with ESMTP id D7CC92E0237 for ; Thu, 13 Mar 2008 03:35:14 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id A3B6CD5370; Thu, 13 Mar 2008 15:35:09 +0900 (WST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 8AF611E0435; Thu, 13 Mar 2008 15:35:09 +0900 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id yeCYzNaQqCZp; Thu, 13 Mar 2008 15:35:09 +0900 (WST) Received: from [10.0.0.125] (dhcp-125.localnet [10.0.0.125]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTP id EF26D1E0434; Thu, 13 Mar 2008 15:35:08 +0900 (WST) Message-ID: <47D8CB14.8020400@postnewspapers.com.au> Date: Thu, 13 Mar 2008 15:35:00 +0900 From: Craig Ringer User-Agent: Thunderbird 2.0.0.12 (Windows/20080213) MIME-Version: 1.0 To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: Repeated execution of identical subqueries References: <47D8A191.6000303@postnewspapers.com.au> <7556.1205385204@sss.pgh.pa.us> In-Reply-To: <7556.1205385204@sss.pgh.pa.us> X-Enigmail-Version: 0.95.6 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: 200803/269 X-Sequence-Number: 29223 Tom Lane wrote: > No, not at the moment. In principle the planner could look for such > duplicates, but it'd be wasted cycles so much of the time that I'd be > loath to do it. > Good point - there are better places to spend time, and I imagine it'd be an expensive thing to check too. > There is work afoot to implement the SQL:2003 "WITH" syntax, which > I think would offer a syntactic solution to your problem. Yes, it would. In fact, I was thinking about the syntax seen in some functional languages - like Haskell's `where' clause - that defines a subexpression available to all parts of the expression. If the SQL:2003 WITH expression is anything like that it'd be very handy indeed. -- Craig Ringer