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 1gcnWF-0008So-FH for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Dec 2018 08:29:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcnVF-0004IJ-Qv for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Dec 2018 08:28:21 +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 1gcnVF-0004IC-J9 for pgsql-hackers@lists.postgresql.org; Fri, 28 Dec 2018 08:28:21 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gcnV8-0003ig-3U for pgsql-hackers@postgresql.org; Fri, 28 Dec 2018 08:28:21 +0000 Received: from vc2.ecl.ntt.co.jp (vc2.ecl.ntt.co.jp [129.60.86.154]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id wBS8SCp6028286 for ; Fri, 28 Dec 2018 17:28:12 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id CB202638CA4 for ; Fri, 28 Dec 2018 17:28:12 +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 BFDCF638C34 for ; Fri, 28 Dec 2018 17:28:12 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id B63FF40075F for ; Fri, 28 Dec 2018 17:28:12 +0900 (JST) Message-ID: <5C25DE9B.5010000@lab.ntt.co.jp> Date: Fri, 28 Dec 2018 17:28:11 +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: postgres_fdw: oddity in costing aggregate pushdown paths References: <5BFD3EAD.2060301@lab.ntt.co.jp> <5BFE1BDE.7010306@lab.ntt.co.jp> <5C010821.7050102@lab.ntt.co.jp> <5C051180.7090804@lab.ntt.co.jp> <5C0639B7.1080006@lab.ntt.co.jp> In-Reply-To: <5C0639B7.1080006@lab.ntt.co.jp> Content-Type: multipart/mixed; boundary="------------040505050602040000030100" 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 This is a multi-part message in MIME format. --------------040505050602040000030100 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit (2018/12/04 17:24), Etsuro Fujita wrote: > (2018/12/03 20:20), Etsuro Fujita wrote: >> (2018/11/30 18:51), Etsuro Fujita wrote: >>> (2018/11/28 13:38), Etsuro Fujita wrote: >>>> BTW another thing I noticed is this comment on costing aggregate >>>> pushdown paths using local statistics in estimate_path_cost_size: >>>> >>>> * Also, core does not care about costing HAVING expressions and >>>> * adding that to the costs. So similarly, here too we are not >>>> * considering remote and local conditions for costing. >>>> >>>> I think this was true when aggregate pushdown went in, but isn't anymore >>>> because of commit 7b6c07547190f056b0464098bb5a2247129d7aa2. So we >>>> should update estimate_path_cost_size so that it accounts for the >>>> selectivity and cost of the HAVING expressions as well? >>> >>> There seems to be no objections, I updated the patch as such. Attached >>> is an updated version of the patch. >> >> I revised some comments a bit and added the commit message. Attached is >> an updated patch. If there are no objections, I'll apply this to HEAD only. > > Done after fixing typos in the commit message. I noticed that I forgot to modify the cost for evaluating the PathTarget for each output row accordingly to this change :(. Attached is a patch for that. Best regards, Etsuro Fujita --------------040505050602040000030100 Content-Type: text/x-patch; name="fix-postgres-fdw-grouping-path-cost.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-postgres-fdw-grouping-path-cost.patch" *** a/contrib/postgres_fdw/postgres_fdw.c --- b/contrib/postgres_fdw/postgres_fdw.c *************** *** 2937,2943 **** estimate_path_cost_size(PlannerInfo *root, run_cost = ofpinfo->rel_total_cost - ofpinfo->rel_startup_cost; run_cost += aggcosts.finalCost * numGroups; run_cost += cpu_tuple_cost * numGroups; ! run_cost += ptarget->cost.per_tuple * numGroups; /* Accout for the eval cost of HAVING quals, if any */ if (root->parse->havingQual) --- 2937,2943 ---- run_cost = ofpinfo->rel_total_cost - ofpinfo->rel_startup_cost; run_cost += aggcosts.finalCost * numGroups; run_cost += cpu_tuple_cost * numGroups; ! run_cost += ptarget->cost.per_tuple * rows; /* Accout for the eval cost of HAVING quals, if any */ if (root->parse->havingQual) --------------040505050602040000030100--