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 1gucUA-0004HF-3O for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Feb 2019 12:20:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gucU8-0000pP-Lq for pgsql-hackers@arkaria.postgresql.org; Fri, 15 Feb 2019 12:20:52 +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 1gucU8-0000pI-EN for pgsql-hackers@lists.postgresql.org; Fri, 15 Feb 2019 12:20:52 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gucU4-0001h5-FC for pgsql-hackers@postgresql.org; Fri, 15 Feb 2019 12:20:52 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama50.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id x1FCKWCc018290; Fri, 15 Feb 2019 21:20:32 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id CD2CFEA7FEB; Fri, 15 Feb 2019 21:20:32 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id B883CEA7FE8; Fri, 15 Feb 2019 21:20:32 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 9D4354005E4; Fri, 15 Feb 2019 21:20:32 +0900 (JST) Message-ID: <5C66AE52.4020605@lab.ntt.co.jp> Date: Fri, 15 Feb 2019 21:19:30 +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: Problems with plan estimates in postgres_fdw References: <87pnz1aby9.fsf@news-spur.riddles.org.uk> <1175.1533220908@sss.pgh.pa.us> <5BB739CD.6040002@lab.ntt.co.jp> <5BBC4140.50403@lab.ntt.co.jp> <5C17A00E.5000005@lab.ntt.co.jp> <5C232F39.9060509@lab.ntt.co.jp> <5C25C7B5.2010802@lab.ntt.co.jp> <5C518631.5080401@lab.ntt.co.jp> <10994.1549559088@localhost> <5C5D778F.3080501@lab.ntt.co.jp> <5C6251A7.40204@lab.ntt.co.jp> <26618.1549971814@localhost> <5C653888.70705@lab.ntt.co.jp> In-Reply-To: <5C653888.70705@lab.ntt.co.jp> Content-Type: multipart/mixed; boundary="------------080705040008020002080500" X-CC-Mail-RelayStamp: 1 To: Antonin Houska Cc: Tom Lane , Andrew Gierth , pgsql-hackers@postgresql.org X-TM-AS-MML: disable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------080705040008020002080500 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit (2019/02/14 18:44), Etsuro Fujita wrote: > (2019/02/12 20:43), Antonin Houska wrote: >> Etsuro Fujita wrote: >>> Here are my review comments: >>> >>> root->upper_targets[UPPERREL_FINAL] = final_target; >>> + root->upper_targets[UPPERREL_ORDERED] = final_target; >>> root->upper_targets[UPPERREL_WINDOW] = sort_input_target; >>> root->upper_targets[UPPERREL_GROUP_AGG] = grouping_target; >>> >>> I think that's a good idea. I think we'll soon need the PathTarget for >>> UPPERREL_DISTINCT, so how about saving that as well like this? >>> >>> root->upper_targets[UPPERREL_FINAL] = final_target; >>> + root->upper_targets[UPPERREL_ORDERED] = final_target; >>> + root->upper_targets[UPPERREL_DISTINCT] = sort_input_target; >>> root->upper_targets[UPPERREL_WINDOW] = sort_input_target; >>> root->upper_targets[UPPERREL_GROUP_AGG] = grouping_target; >> >> I see nothing wrong about this. > > Cool! > >>> Another is about this: >>> >>> /* >>> + * Set reltarget so that it's consistent with the paths. Also it's more >>> + * convenient for FDW to find the target here. >>> + */ >>> + ordered_rel->reltarget = target; >>> >>> I think this is correct if there are no SRFs in the targetlist, but >>> otherwise >>> I'm not sure this is really correct because the relation's reltarget >>> would not >>> match the target of paths added to the relation after >>> adjust_paths_for_srfs(). >> >> I wouldn't expect problem here. create_grouping_paths() also sets the >> reltarget although adjust_paths_for_srfs() can be alled on grouped_rel >> afterwards. > > Yeah, but as I said in a previous email, I think the root->upper_targets > change would be enough at least currently for FDWs to consider > performing post-UPPERREL_GROUP_AGG steps remotely, as shown in my > patches, so I'm inclined to leave the retarget change for future work. So, here is an updated patch. If there are no objections from you or anyone else, I'll commit the patch as a preliminary one for what's proposed in this thread. Best regards, Etsuro Fujita --------------080705040008020002080500 Content-Type: text/x-patch; name="0001-Save-PathTargets-for-distinct-ordered-relations-in-r.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Save-PathTargets-for-distinct-ordered-relations-in-r.pa"; filename*1="tch" From 5ade52b576cb8403d3a079fecf4c938225cc3bd7 Mon Sep 17 00:00:00 2001 From: Etsuro Fujita Date: Fri, 15 Feb 2019 21:13:36 +0900 Subject: [PATCH] Save PathTargets for distinct/ordered relations in root->upper_targets[] Previously, we only saved the PathTargets for grouping, window and final relations in root->upper_targets[] in grouping_planner. To improve the convenience of extensions, save the PathTargets for distinct and ordered relations as well. Author: Antonin Houska, with an additional change by me Discussion: https://postgr.es/m/10994.1549559088@localhost --- src/backend/optimizer/plan/planner.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index ddb86bd0c3..a4ec4456e5 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -2035,6 +2035,8 @@ grouping_planner(PlannerInfo *root, bool inheritance_update, * of the corresponding upperrels might not be needed for this query. */ root->upper_targets[UPPERREL_FINAL] = final_target; + root->upper_targets[UPPERREL_ORDERED] = final_target; + root->upper_targets[UPPERREL_DISTINCT] = sort_input_target; root->upper_targets[UPPERREL_WINDOW] = sort_input_target; root->upper_targets[UPPERREL_GROUP_AGG] = grouping_target; -- 2.19.2 --------------080705040008020002080500--