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 1lvaUG-00084N-PX for pgsql-general@arkaria.postgresql.org; Tue, 22 Jun 2021 07:06:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lvaUE-0001Wz-1l for pgsql-general@arkaria.postgresql.org; Tue, 22 Jun 2021 07:06:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lvaUD-0001Wr-DG for pgsql-general@lists.postgresql.org; Tue, 22 Jun 2021 07:06:17 +0000 Received: from srvimsva2.dst.dk ([91.208.143.64]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lvaU9-0002NC-A7 for pgsql-general@lists.postgresql.org; Tue, 22 Jun 2021 07:06:16 +0000 Received: from srvimsva2.dst.dk (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 97427104093 for ; Tue, 22 Jun 2021 09:06:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dst.dk; s=dmz20180119; t=1624345571; bh=fWwaLYVhPPcRpShUICo43sEfqSCOEac66DOk7rbk/Mc=; h=From:To:Date; b=c4xK2Z6vBidxkxLtvJq0JCIvNV3thkanS46MMrlo7I+XG3bkMtqOftQ6sfMYJnfwq pC1npNH7mxoPxBf8uzJnqMyKRR9DlBWRjRMUJeMPQ/od0138JjYJSux47hHP6eZZXS rGZgOZyVc2UyhVOlgcoPu9z0RoMdzgNF2iNYcBGc= Received: from srvimsva2.dst.dk (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 82137104091 for ; Tue, 22 Jun 2021 09:06:11 +0200 (CEST) Received: from Sepo.dst.dk (unknown [192.168.64.11]) by srvimsva2.dst.dk (Postfix) with ESMTP for ; Tue, 22 Jun 2021 09:06:11 +0200 (CEST) Received: from srvexc9.dst.local ([172.30.32.49]) by Sepo.dst.dk (JAMES SMTP Server 2.3.2-1) with SMTP ID 614 for ; Tue, 22 Jun 2021 09:06:11 +0200 (CEST) Received: from srvexc8.dst.local (172.30.32.48) by srvexc9.dst.local (172.30.32.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Tue, 22 Jun 2021 09:06:11 +0200 Received: from srvexc8.dst.local ([fe80::9df8:5de5:1bf2:8b3b]) by srvexc8.dst.local ([fe80::9df8:5de5:1bf2:8b3b%2]) with mapi id 15.01.2242.008; Tue, 22 Jun 2021 09:06:11 +0200 From: Niels Jespersen To: "pgsql-general@lists.postgresql.org" Subject: cpu-intensive immutable function and parallel scan Thread-Topic: cpu-intensive immutable function and parallel scan Thread-Index: AddnMo9a8hAZPET0SOW9MzoVWEYqdg== Date: Tue, 22 Jun 2021 07:06:10 +0000 Message-ID: Accept-Language: da-DK, en-US Content-Language: da-DK X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.30.33.38] Content-Type: multipart/alternative; boundary="_000_c800b7a24a95419aaebf4e6ec31d8f57dstdk_" MIME-Version: 1.0 X-TM-AS-GCONF: 00 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_c800b7a24a95419aaebf4e6ec31d8f57dstdk_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello all I have a cpu-intensive plpython3u function that computes a result on the va= lue from a single column value from a simple select.This looks largely like= this. select function_name (t1.val1, 'constant1') from t1 where t1.p =3D '202012_= 1' and t1.val1 is not null; The function is marked immutable and parallel safe. The time spent in the function is quite substantial. The same execution pla= n for a query that invokes the funtion and a query that does not results in= a 15-times slowdown. Explain analyze show that both queries use 5 parallel= workers. I think I could achieve some speedup by parallelizing further, distributing= the cpu-work among additional workers. But, how do I achive that best? In Oracle I would either use a parallel-hint or an alter session force para= llel query parallel 8. Regards Niels --_000_c800b7a24a95419aaebf4e6ec31d8f57dstdk_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hello all

 

I have a cpu-intensive plpython3u function that compute= s a result on the value from a single column value from a simple select.Thi= s looks largely like this.

 

select function_name (t1.val1, 'constant1') from t1 whe= re t1.p =3D '202012_1' and t1.val1 is not null;

 

The function is marked immutable and parallel safe.

 

The time spent in the function is quite substantial. Th= e same execution plan for a query that invokes the funtion and a query that= does not results in a 15-times slowdown. Explain analyze show that both queries use 5 parallel workers. <= /p>

 

I think I could achieve some speedup by parallelizing f= urther, distributing the cpu-work among additional workers. But, how do I a= chive that best?

 

In Oracle I would either use a parallel-hint or an alte= r session force parallel query parallel 8.

 

Regards Niels

 

--_000_c800b7a24a95419aaebf4e6ec31d8f57dstdk_--