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 1lvgTA-0003HN-1C for pgsql-general@arkaria.postgresql.org; Tue, 22 Jun 2021 13:29:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lvgT9-0002AJ-1n for pgsql-general@arkaria.postgresql.org; Tue, 22 Jun 2021 13:29:35 +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 1lvgT8-0002AB-PS for pgsql-general@lists.postgresql.org; Tue, 22 Jun 2021 13:29:34 +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 1lvgT6-0004F0-QD for pgsql-general@lists.postgresql.org; Tue, 22 Jun 2021 13:29:33 +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 15MDTSlx1713128; Tue, 22 Jun 2021 09:29:28 -0400 From: Tom Lane To: David Rowley cc: Niels Jespersen , "pgsql-general@lists.postgresql.org" Subject: Re: cpu-intensive immutable function and parallel scan In-reply-to: References: Comments: In-reply-to David Rowley message dated "Tue, 22 Jun 2021 19:09:50 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1713126.1624368568.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 22 Jun 2021 09:29:28 -0400 Message-ID: <1713127.1624368568@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Tue, 22 Jun 2021 at 19:06, Niels Jespersen wrote: >> I think I could achieve some speedup by parallelizing further, distribu= ting the cpu-work among additional workers. But, how do I achive that best= ? > You'll want to ensure max_parallel_workers_per_gather is set high > enough and you have max_parallel_workers set to something high enough. > You can then do: > alter table t1 set (parallel_workers =3D ); Also, if you don't have a fairly high COST value set on the function, try raising that to make the planner understand that it's expensive. My recollection is that the amount of parallelism it goes for is partly predicated on the estimated query cost. regards, tom lane