Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fiOh9-0001EW-EE for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jul 2018 18:39:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fiOh7-0000Ja-R7 for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Jul 2018 18:39:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fiOh7-0000JT-Fa for pgsql-hackers@lists.postgresql.org; Wed, 25 Jul 2018 18:39:29 +0000 Received: from smtp17.dreamhost.com ([64.90.62.186] helo=pdx1-sub0-mail-a10.g.dreamhost.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fiOh4-0000UJ-Bb for pgsql-hackers@postgresql.org; Wed, 25 Jul 2018 18:39:27 +0000 Received: from pdx1-sub0-mail-a10.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTP id 09E2E80E07; Wed, 25 Jul 2018 11:39:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=cryptonector.com; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=cryptonector.com; bh=A6cg6zmoN8HJMH bZA7o6p44metQ=; b=wmVq2qZ+sNckfqim2vZrrvJ1yZF4BjnJwodtloTJZcxWsJ SWfr3CQssV44wPnl70rDLa0SCLx1CmEPyussVIjJWhinE2bgF9yjZHVBERm/ib58 JVVRxm/z2Hoq/MQjHukN9t3mLjEna3BvOGa6hwr+Quh7BJR8sDc3FXDNl3lho= Received: from localhost (cpe-70-123-158-140.austin.res.rr.com [70.123.158.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: nico@cryptonector.com) by pdx1-sub0-mail-a10.g.dreamhost.com (Postfix) with ESMTPSA id BC8207FD88; Wed, 25 Jul 2018 11:39:23 -0700 (PDT) Date: Wed, 25 Jul 2018 13:39:19 -0500 From: Nico Williams To: Tom Lane Cc: Andres Freund , Jeremy Finzel , Andrew Gierth , pgsql-hackers@postgresql.org Subject: Re: Early WIP/PoC for inlining CTEs Message-ID: <20180725183918.GP5695@localhost> References: <87sh48ffhb.fsf@news-spur.riddles.org.uk> <20180724231010.quiaae5qyfrreiyj@alap3.anarazel.de> <21487.1532476159@sss.pgh.pa.us> <20180724235416.c7c4az6kjxyszkgt@alap3.anarazel.de> <21958.1532476669@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <21958.1532476669@sss.pgh.pa.us> User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Tue, Jul 24, 2018 at 07:57:49PM -0400, Tom Lane wrote: > Andres Freund writes: > > On 2018-07-24 19:49:19 -0400, Tom Lane wrote: > >> However, a singly-referenced SELECT CTE could reasonably be treated as > >> equivalent to a sub-select-in-FROM, and then you would have the same > >> mechanisms for preventing inlining as you do for those cases, > >> e.g. OFFSET 0. And sticking in OFFSET 0 would be backwards-compatible > >> too: your code would still work the same in older releases, unlike if > >> we invent new syntax for this. > > > I still think this is just doubling down on prior mistakes. > > Not following what you think a better alternative is? I'd be the > first to agree that OFFSET 0 is a hack, but people are used to it. > > Assuming that we go for inline-by-default for at least some cases, > there's a separate discussion to be had about whether it's worth > making a planner-control GUC to force the old behavior. I'm not > very excited about that, but I bet some people will be. It is widely known that CTEs in PG are optimizer barriers. That actually is useful, and I do make use of that fact (though I'm not proud of it). My proposal is that PG add an extension for specifying that a CTE is to be materialized (barrier) or not (then inlined). Nico --