Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5aXR-0000yn-H8 for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Dec 2022 22:47:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p5aXQ-0005lW-EA for pgsql-bugs@arkaria.postgresql.org; Wed, 14 Dec 2022 22:47:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5aXQ-0005lN-6F for pgsql-bugs@lists.postgresql.org; Wed, 14 Dec 2022 22:47:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5aXN-0001R4-SE for pgsql-bugs@lists.postgresql.org; Wed, 14 Dec 2022 22:47:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2BEMletT2998994; Wed, 14 Dec 2022 17:47:41 -0500 From: Tom Lane To: Nathaniel Hazelton cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: BUG #17721: A completely unused CTE negatively affect Query Plan In-reply-to: References: <17721-a660b93948b165a7@postgresql.org> <2784036.1671042328@sss.pgh.pa.us> Comments: In-reply-to Nathaniel Hazelton message dated "Wed, 14 Dec 2022 22:14:07 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2998992.1671058060.1@sss.pgh.pa.us> Date: Wed, 14 Dec 2022 17:47:40 -0500 Message-ID: <2998993.1671058060@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Nathaniel Hazelton writes: > The CTE in that location was emulating a view in which we have a CTE - > which responds the same way. Does this mean CTEs can never be used in > views that could be flattened without affecting performance? You've got a view with an unused CTE? Why? But at any rate, yes, the presence of a CTE is an optimization fence: we can't flatten the subquery containing it without losing the query level at which the CTE should be evaluated. Perhaps there are special cases where that could be relaxed, but nobody's tried very hard. regards, tom lane