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 1g8N9R-000778-FC for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Oct 2018 10:16:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g8N9P-0001XA-MR for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Oct 2018 10:16:03 +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 1g8N9P-0001X3-FM for pgsql-hackers@lists.postgresql.org; Fri, 05 Oct 2018 10:16:03 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g8N9K-0000qc-3k for pgsql-hackers@postgresql.org; Fri, 05 Oct 2018 10:16:03 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id w95AFuV0028743; Fri, 5 Oct 2018 19:15:56 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 39789EA8853; Fri, 5 Oct 2018 19:15:56 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 2EECDEA8851; Fri, 5 Oct 2018 19:15:56 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 29D4A40020F; Fri, 5 Oct 2018 19:15:56 +0900 (JST) Message-ID: <5BB739CD.6040002@lab.ntt.co.jp> Date: Fri, 05 Oct 2018 19:15:41 +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> In-Reply-To: <1175.1533220908@sss.pgh.pa.us> 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/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. I'm sorry that I'm really late for the party. Best regards, Etsuro Fujita