Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iL1x7-0004Ry-NT for pgsql-general@arkaria.postgresql.org; Thu, 17 Oct 2019 09:20:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iL1x6-0000CF-0W for pgsql-general@arkaria.postgresql.org; Thu, 17 Oct 2019 09:20:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iL1x5-0000C8-NL for pgsql-general@lists.postgresql.org; Thu, 17 Oct 2019 09:20:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iL1x3-0003gn-0G for pgsql-general@postgresql.org; Thu, 17 Oct 2019 09:20:11 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x9H9K4fo018541; Thu, 17 Oct 2019 05:20:04 -0400 From: Tom Lane To: Erwin Brandstetter cc: pgsql-general@postgresql.org Subject: Re: Can functions containing a CTE be PARALLEL SAFE? In-reply-to: References: Comments: In-reply-to Erwin Brandstetter message dated "Thu, 17 Oct 2019 05:09:17 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <19530.1571304003.1@sss.pgh.pa.us> Date: Thu, 17 Oct 2019 11:20:03 +0200 Message-ID: <19531.1571304003@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Erwin Brandstetter writes: >> The following operations are always parallel restricted. >> - Scans of common table expressions (CTEs). > Now I am unsure whether I can use `PARALLEL SAFE` for functions containing > a CTE (while fulfilling all other criteria)? AFAIR, the reason for treating CTEs as parallel restricted is simply to guarantee single evaluation of the CTE. Within a function, that would only matter per-function-execution, so I can't see why a function containing such a query couldn't be pushed down to workers for execution. regards, tom lane