Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id CE4DB65045D for ; Mon, 28 Jul 2008 20:04:34 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 56246-01-2 for ; Mon, 28 Jul 2008 20:04:21 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id AB62C650433 for ; Mon, 28 Jul 2008 20:04:16 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m6SN4Ehs000204; Mon, 28 Jul 2008 19:04:14 -0400 (EDT) To: Martijn van Oosterhout cc: Andrew Gierth , pgsql-hackers@postgresql.org Subject: Re: WITH RECUSIVE patches 0723 In-reply-to: <20080728222446.GC24856@svana.org> References: <20080725001513.GF16438@fetter.org> <20080725.092652.105178884.t-ishii@sraoss.co.jp> <87r69gs967.fsf@news-spur.riddles.org.uk> <20080728.162925.23020498.t-ishii@sraoss.co.jp> <19882.1217256991@sss.pgh.pa.us> <87myk1rg4z.fsf@news-spur.riddles.org.uk> <20080728222446.GC24856@svana.org> Comments: In-reply-to Martijn van Oosterhout message dated "Tue, 29 Jul 2008 00:24:46 +0200" Date: Mon, 28 Jul 2008 19:04:14 -0400 Message-ID: <203.1217286254@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200807/1336 X-Sequence-Number: 121596 Martijn van Oosterhout writes: > Since the problem is using the result of a WITH clause more than once, > would it be sufficient to simply detect that case and bail? You don't > want materialisation is most cases, there's just a few where it is > needed. Really? I tried googling to see what other people thought that the WITH clause was for, and the first relevant hit I got was this one: http://www.oracle-developer.net/display.php?id=212 which certainly treats it as a key part of the feature. My thought is that we could optimize away materialization in cases where we can tell it's not needed (no volatile functions and/or no multiple scans of the subquery). But not being able to do it means we've implemented the feature incorrectly. regards, tom lane