Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dwRJi-0007qH-Me for pgsql-performance@arkaria.postgresql.org; Mon, 25 Sep 2017 11:12:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dwRJi-0004vz-3Z for pgsql-performance@arkaria.postgresql.org; Mon, 25 Sep 2017 11:12:50 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dwRHx-0001rS-Sa for pgsql-performance@postgresql.org; Mon, 25 Sep 2017 11:11:01 +0000 Received: from mail2.code-sourcery.de ([138.201.66.53]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dwRHu-0001w0-DX for pgsql-performance@postgresql.org; Mon, 25 Sep 2017 11:11:00 +0000 Received: from lxtobi.voipfuture.com (unknown [213.238.34.194]) by mail2.code-sourcery.de (Postfix) with ESMTPSA id 3304F1FC8D for ; Mon, 25 Sep 2017 13:10:57 +0200 (CEST) To: pgsql-performance@postgresql.org From: Tobias Gierke Subject: Parallel sequential scan not supported for stored procedure with RETURN QUERY EXECUTE ? Message-ID: <57255ffe-f51b-aba0-95e5-7be3c9b88bb9@code-sourcery.de> Date: Mon, 25 Sep 2017 13:10:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi, We're using PostgreSQL 9.6.3 on Linux. I have a pl/pgsql stored procedure that is not utilizing the new parallel sequential scan feature although manually running the same query does (assuming the same settings/optimizer hints are used ofc). A rough outline of the stored procedure (omitting all the boring parts) is given below ; basically I'm dynamically creating a SQL statement and then using RETURN QUERY EXECUTE to run it. EXPLAIN'ing the query that's printed by the "RAISE NOTICE" (with the same options as the stored procedure) produces a plan that uses parallel execution but invoking the stored procedure obviously does not as the execution time is orders of magnitudes slower. Any ideas ? Thanks, Tobias --------------------------------- CREATE OR REPLACE FUNCTION do_stuff(....lots of parameters...) RETURNS SETOF importer.statistic_type AS $BODY$ DECLARE   _sql text; BEGIN     _sql := 'SELECT ''' || _hostname || '''::text AS hostname,'                   'interval_start, '                   'total_filesize, '                   'total_filecount, '                   'EXTRACT(EPOCH FROM combined_import_time_seconds) AS combined_import_time_seconds, '                   'min_throughput, '                   'max_throughput, '                   ''''|| _filetype ||'''::text AS filetype, '                   'busy_seconds '             'FROM ( SELECT '                           'vf_cut_func(starttime' || _cut_func_parameter || ') AS interval_start, '                           'sum(filesize) AS total_filesize, '                           'count(*) AS total_filecount, '                           'sum( endtime-starttime ) AS combined_import_time_seconds, '                           'min(filesize/EXTRACT(EPOCH FROM endtime-starttime)) AS min_throughput, '                           'max(filesize/EXTRACT(EPOCH FROM endtime-starttime)) AS max_throughput, '                           'busy_time_seconds( tstzrange(starttime,MIN(endtime,  vf_cut_func(starttime' || _cut_func_parameter || ') + ' || _interval || ') ) ) AS busy_seconds '                     'FROM importer.log '                     'WHERE filetype = '''|| _filetype ||''' '                       'AND starttime >= ''' || _starttime || ''' '                       'AND starttime < ''' || _endtime || ''' '                       'AND hostname=''' || _hostname || ''' '                     'GROUP BY vf_cut_func(starttime' || _cut_func_parameter || '), hostname) AS foo;';   RAISE NOTICE '_sql:%', _sql;   RETURN QUERY EXECUTE _sql; END; $BODY$   LANGUAGE plpgsql VOLATILE   SET "TimeZone" TO 'utc'   set parallel_setup_cost TO 1   set max_parallel_workers_per_gather TO 4   set min_parallel_relation_size TO 1   set enable_indexscan TO false   set enable_bitmapscan TO false; -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance