Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TYfpv-0006ZM-IL for pgsql-performance@postgresql.org; Wed, 14 Nov 2012 16:29:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TYfpt-0007NA-BB for pgsql-performance@postgresql.org; Wed, 14 Nov 2012 16:29:11 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id qAEGT3gX020463; Wed, 14 Nov 2012 11:29:03 -0500 (EST) From: Tom Lane To: David Greco cc: Andrew Dunstan , "pgsql-performance@postgresql.org" Subject: Re: SOLVED - RE: Poor performance using CTE In-reply-to: <187F6C10D2931A4386EE8E58E13857F61291D897@BY2PRD0811MB415.namprd08.prod.outlook.com> References: <187F6C10D2931A4386EE8E58E13857F61291D897@BY2PRD0811MB415.namprd08.prod.outlook.com> Comments: In-reply-to David Greco message dated "Wed, 14 Nov 2012 16:18:42 +0000" Date: Wed, 14 Nov 2012 11:29:03 -0500 Message-ID: <20462.1352910543@sss.pgh.pa.us> X-Pg-Spam-Score: -2.1 (--) X-Archive-Number: 201211/167 X-Sequence-Number: 48533 David Greco writes: > Thanks, that did the trick. Though I'm still not clear as to why. PG treats WITH as an optimization fence --- the WITH query will be executed pretty much as-is. It may be that Oracle flattens the query somehow; though if you're using black-box functions in both cases, it's not obvious where the optimizer could get any purchase that way. regards, tom lane