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 1h0iH2-0006oi-NP for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2019 07:44:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h0iH1-0005YX-EA for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2019 07:44:31 +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 1h0iH1-0005YQ-5O for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2019 07:44:31 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h0iGx-00061r-1B for pgsql-hackers@postgresql.org; Mon, 04 Mar 2019 07:44:30 +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 mx1.mailbox.org (Postfix) with ESMTPS id D9DFF4BDD1; Mon, 4 Mar 2019 08:44:24 +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=1551685462; 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=2Jd5c4OvuQVn/YsRnF4KpIPpkVNGKzHVMDDMu6BkCG8=; b=v+fkuZf+vuWboDjcOC4GwKuJ/8q/+pVw7A+Byo9W78RO/o+ybzgTvt+Jjd3EZDi3CHnxwY 23o2r/DKOsN6VGp7MFjKwXyqGnZ7/oAPgYeVavw1iKWlJj33I2676pLeT0vmy9GFLtO2PL tfHd6atf+truNQTFa7wP/YVlBTfPcJRBoNqBGjLeUIgabKoUm8EzdNmFv1Nn9dX7lImjUo HMd1LVOFpaUIIkg/F8yX4z5qOIwmPgRK4yExP0MrxEeMWp5w6UEHTCt4Aw7/b5sjnvVbuR SqvczwNzjiQOdVgN3vsu1lWdUUcq6trgFfWc7nwd2DyDV+IsbjaoI4a7iVBlEg== Received: from smtp2.mailbox.org ([80.241.60.241]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id YQIgDOsim2S8; Mon, 4 Mar 2019 08:44:17 +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: <26193.1551685577.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Mon, 04 Mar 2019 08:46:17 +0100 Message-ID: <26194.1551685577@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: > > It's still unclear to me why add_foreign_ordered_paths() passes the in= put > > relation (input_rel) to estimate_path_cost_size(). If it passed the ou= tput rel > > (i.e. ordered_rel in this case) like add_foreign_grouping_paths() does= , then > > foreignrel->reltarget should contain the random() function. (What I se= e now is > > that create_ordered_paths() leaves ordered_rel->reltarget empty, but t= hat's > > another problem to be fixed.) > > > > Do you still see a reason to call estimate_path_cost_size() this way? > = > Yeah, the reason for that is because we can estimate the costs of sortin= g for > the final scan/join relation using the existing code as-is that estimate= s the > costs of sorting for base or join relations, except for tlist eval cost > adjustment. As you mentioned, we could pass ordered_rel to > estimate_path_cost_size(), but if so, I think we would need to get input= _rel > (ie, the final scan/join relation) from ordered_rel within > estimate_path_cost_size(), to use that code, which would not be great. After some more thought I suggest that estimate_path_cost_size() is redesi= gned before your patch gets applied. The function is quite hard to read if - wi= th your patch applied - the "foreignrel" argument sometimes means the output relation and other times the input one. I takes some effort to "switch context" between these two perspectives when I read the code. Perhaps both input and output relation should be passed to the function no= w, and maybe also UpperRelationKind of the output relation. And maybe it's ev= en worth moving some code into a subroutine that handles only the upper relat= ion. Originally the function could only handle base relations, then join relati= on was added, then one kind of upper relation (UPPERREL_GROUP_AGG) was added = and eventually the function will need to handle multiple kinds of upper relation. It should be no surprise if such an amount of changes makes the original signature insufficient. -- = Antonin Houska https://www.cybertec-postgresql.com