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 1gyvzP-0006co-J2 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Feb 2019 09:58:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyvzM-0008GW-R0 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Feb 2019 09:58:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gyvzL-0008GP-S4 for pgsql-hackers@lists.postgresql.org; Wed, 27 Feb 2019 09:58:56 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyvzC-0007R5-MK for pgsql-hackers@postgresql.org; Wed, 27 Feb 2019 09:58:53 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x1R9wjN8023534 for ; Wed, 27 Feb 2019 18:58:45 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 01ECF6392D8 for ; Wed, 27 Feb 2019 18:58:45 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id EAFF8639289 for ; Wed, 27 Feb 2019 18:58:44 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id E78B7400AD3 for ; Wed, 27 Feb 2019 18:58:44 +0900 (JST) Message-ID: <5C765E99.9070202@lab.ntt.co.jp> Date: Wed, 27 Feb 2019 18:55:37 +0900 From: Etsuro Fujita User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 Subject: Re: Oddity with parallel safety test for scan/join target in grouping_planner References: <5C75303E.8020303@lab.ntt.co.jp> In-Reply-To: <5C75303E.8020303@lab.ntt.co.jp> Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-CC-Mail-RelayStamp: 1 To: Pg Hackers X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk (2019/02/26 21:25), Etsuro Fujita wrote: > While working on [1], I noticed $Subject, that is: > > /* > * If we have grouping or aggregation to do, the topmost scan/join > * plan node must emit what the grouping step wants; otherwise, it > * should emit grouping_target. > */ > have_grouping = (parse->groupClause || parse->groupingSets || > parse->hasAggs || root->hasHavingQual); > if (have_grouping) > { > scanjoin_target = make_group_input_target(root, final_target); > --> scanjoin_target_parallel_safe = > is_parallel_safe(root, (Node *) grouping_target->exprs); > } > else > { > scanjoin_target = grouping_target; > scanjoin_target_parallel_safe = grouping_target_parallel_safe; > } > > The parallel safety of the final scan/join target is determined from the > grouping target, not that target, which would cause to generate inferior > parallel plans as shown below: > > pgbench=# explain verbose select aid+bid, sum(abalance), random() from > pgbench_accounts group by aid+bid; > QUERY PLAN > ------------------------------------------------------------------------------------------------------------ > GroupAggregate (cost=137403.01..159903.01 rows=1000000 width=20) > Output: ((aid + bid)), sum(abalance), random() > Group Key: ((pgbench_accounts.aid + pgbench_accounts.bid)) > -> Sort (cost=137403.01..139903.01 rows=1000000 width=8) > Output: ((aid + bid)), abalance > Sort Key: ((pgbench_accounts.aid + pgbench_accounts.bid)) > -> Gather (cost=10.00..24070.67 rows=1000000 width=8) > Output: (aid + bid), abalance > Workers Planned: 2 > -> Parallel Seq Scan on public.pgbench_accounts > (cost=0.00..20560.67 rows=416667 width=12) > Output: aid, bid, abalance > (11 rows) > > The final scan/join target {(aid + bid), abalance} is definitely > parallel safe, but the target evaluation isn't parallelized across > workers, which is not good. Attached is a patch for fixing this. I added this to the upcoming commitfest. Best regards, Etsuro Fujita