Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g9kt2-0003IV-7X for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Oct 2018 05:48:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g9kt0-0000LB-1c for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Oct 2018 05:48:50 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1g9ksz-0000L4-Qv for pgsql-hackers@lists.postgresql.org; Tue, 09 Oct 2018 05:48:49 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g9ksw-0004XD-K7 for pgsql-hackers@postgresql.org; Tue, 09 Oct 2018 05:48:49 +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 w995mh80018522; Tue, 9 Oct 2018 14:48:43 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 86A5E6385F6; Tue, 9 Oct 2018 14:48:43 +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 79C1A638552; Tue, 9 Oct 2018 14:48:43 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 6B518400234; Tue, 9 Oct 2018 14:48:43 +0900 (JST) Message-ID: <5BBC4140.50403@lab.ntt.co.jp> Date: Tue, 09 Oct 2018 14:48:48 +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> In-Reply-To: <5BB739CD.6040002@lab.ntt.co.jp> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-CC-Mail-RelayStamp: 1 To: Tom Lane Cc: 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 (2018/10/05 19:15), Etsuro Fujita wrote: > (2018/08/02 23:41), Tom Lane wrote: >> Andrew Gierth writes: >>> [ postgres_fdw is not smart about exploiting fast-start plans ] >> >> Yeah, that's basically not accounted for at all in the current design. >> >>> One possibility: would it be worth adding an option to EXPLAIN that >>> makes it assume cursor_tuple_fraction? >> >> [ handwaving ahead ] >> >> I wonder whether it could be done without destroying postgres_fdw's >> support for old servers, by instead including a LIMIT in the query sent >> for explaining. The trick would be to know what value to put as the >> limit, though. It'd be easy to do if we were willing to explain the query >> twice (the second time with a limit chosen as a fraction of the rowcount >> seen the first time), but man that's an expensive solution. >> >> Another component of any real fix here would be to issue "SET >> cursor_tuple_fraction" before opening the execution cursor, so as to >> ensure that we actually get an appropriate plan on the remote side. >> >> If we could tell whether there's going to be any use in fast-start plans, >> it might make sense to build two scan paths for a foreign table, one >> based >> on a full-table scan and one based on EXPLAIN ... LIMIT 1. This still >> means two explain requests, which is why I'm not thrilled about doing it >> unless there's a high probability of the extra explain being useful. > > Agreed, but ISTM that to address the original issue, it would be enough > to jsut add LIMIT (or ORDER BY LIMIT) pushdown to postgres_fdw based on > the upper-planner-pathification work. Will work on it unless somebody else wants to. Best regards, Etsuro Fujita