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 1h15Ar-0006la-3a for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Mar 2019 08:11:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h15Ap-0005Pt-OB for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Mar 2019 08:11:39 +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 1h15Ap-0005Pm-DX for pgsql-hackers@lists.postgresql.org; Tue, 05 Mar 2019 08:11:39 +0000 Received: from tama50.ecl.ntt.co.jp ([129.60.39.147]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h15Am-0004Nb-HB for pgsql-hackers@postgresql.org; Tue, 05 Mar 2019 08:11:38 +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 x258BKai013353; Tue, 5 Mar 2019 17:11:20 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 41A4D638F27; Tue, 5 Mar 2019 17:11:20 +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 363B3638B08; Tue, 5 Mar 2019 17:11:20 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 2950F40069C; Tue, 5 Mar 2019 17:11:20 +0900 (JST) Message-ID: <5C7E2F26.8020402@lab.ntt.co.jp> Date: Tue, 05 Mar 2019 17:11:18 +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> <19433.1549962210@localhost> <5C669DFD.30002@lab.ntt.co.jp> <16616.1550234762@localhost> <5C6A5FD3.8080102@lab.ntt.co.jp> <30524.1550499671@localhost> <5C6BBD7A.1030702@lab.ntt.co.jp> <29190.1550843669@localhost> <5C73C403.7080109@lab.ntt.co.jp> <7273.1551438041@localhost> <5C7928C7.50507@lab.ntt.co.jp> <12892.1551456865@localhost> In-Reply-To: <12892.1551456865@localhost> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 (2019/03/02 1:14), Antonin Houska wrote: > Etsuro Fujita wrote: >> (2019/03/01 20:00), Antonin Houska wrote: >> Sorry, my explanation was not enough again, but I showed that query ("SELECT >> a+b, random() FROM foreign_table GROUP BY a+b ORDER BY a+b;") to explain why >> the following code bit is needed: >> >> + /* >> + * If this includes an UPPERREL_ORDERED step, the given target, which >> + * would be the final target to be applied to the resulting path, >> might >> + * have different expressions from the underlying relation's reltarget >> + * (see make_sort_input_target()); adjust tlist eval costs. >> + */ >> + if (fpextra&& fpextra->target != foreignrel->reltarget) >> + { >> + QualCost oldcost = foreignrel->reltarget->cost; >> + QualCost newcost = fpextra->target->cost; >> + >> + startup_cost += newcost.startup - oldcost.startup; >> + total_cost += newcost.startup - oldcost.startup; >> + total_cost += (newcost.per_tuple - oldcost.per_tuple) * rows; >> + } > > Maybe I undestand now. Do the expressions (newcost.* - oldcost.*) reflect the > fact that, for the query > > SELECT a+b, random() FROM foreign_table GROUP BY a+b ORDER BY a+b; > > the UPPERREL_ORDERED stage only needs to evaluate the random() function > because (a + b) was already evaluated during the UPPERREL_GROUP_AGG stage? Yeah, I think so. Best regards, Etsuro Fujita