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 1gzkmE-0004Rc-RG for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Mar 2019 16:12:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzkmD-00022p-ED for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Mar 2019 16:12:45 +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 1gzkmD-00022i-2c for pgsql-hackers@lists.postgresql.org; Fri, 01 Mar 2019 16:12:45 +0000 Received: from mx2a.mailbox.org ([2001:67c:2050:104:0:2:25:2] helo=mx2.mailbox.org) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gzkm9-0005Oy-18 for pgsql-hackers@postgresql.org; Fri, 01 Mar 2019 16:12:43 +0000 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 1EFEAA10D3; Fri, 1 Mar 2019 17:12:35 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=MBO0001; t=1551456753; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MxWjalyJZz/n40oI6z+LIFHfsw+fjfdfyj7NtEz7gdQ=; b=eKLjciwDZZOqcx6COQSBIS/RZKNCaFO/xbr29Jo8Ui5rEvtbntoF9Jh1M2KbL06XXaMs2n kmmbIlbaaXM/XY03x57RGx5HPv0BI1HkNmc3ghNEUl10hZiyu2xXK+jhS53be39v10v/hA OQkomwnVTiBL2ggvIwYm1M3y4tOrlgCTG8TVLaZvri3ZuHxm/fWAG9FtQ+CaulKuRYkyRV lTKYfTsCONJjaxewyC1/ObJSQBtafJ0fIUVVRTOhKnVIn1FyZw8eixvc6L7gy6v4PilxuA jVlH1ZSZwCnGXSMw3g7H7JIFETVsN3R9t20Q4V+eLGzVYWIwwafYQeYy030nxg== Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id 4Y2OufGU16Pi; Fri, 1 Mar 2019 17:12:25 +0100 (CET) From: Antonin Houska To: Etsuro Fujita cc: Tom Lane , Andrew Gierth , pgsql-hackers@postgresql.org Subject: Re: Problems with plan estimates in postgres_fdw In-reply-to: <5C7928C7.50507@lab.ntt.co.jp> 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> Comments: In-reply-to Etsuro Fujita message dated "Fri, 01 Mar 2019 21:42:47 +0900." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12891.1551456865.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Fri, 01 Mar 2019 17:14:25 +0100 Message-ID: <12892.1551456865@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Etsuro Fujita wrote: > (2019/03/01 20:00), Antonin Houska wrote: > > Etsuro Fujita wrote: > > I used gdb to help me understand, however the condition > > > > if (fpextra&& !IS_UPPER_REL(foreignrel)) > > > > never evaluated to true with the query above. > = > Sorry, my explanation was not enough again, but I showed that query ("SE= LECT > 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 rel= target > + * (see make_sort_input_target()); adjust tlist eval costs. > + */ > + if (fpextra&& fpextra->target !=3D foreignrel->reltarget) > + { > + QualCost oldcost =3D foreignrel->reltarget->cost; > + QualCost newcost =3D fpextra->target->cost; > + > + startup_cost +=3D newcost.startup - oldcost.startup; > + total_cost +=3D newcost.startup - oldcost.startup; > + total_cost +=3D (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? -- = Antonin Houska https://www.cybertec-postgresql.com