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 1gyCkr-0005rS-N8 for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Feb 2019 09:40:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyCkp-0008WN-K5 for pgsql-hackers@arkaria.postgresql.org; Mon, 25 Feb 2019 09:40:55 +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 1gyCkp-0008TG-BD for pgsql-hackers@lists.postgresql.org; Mon, 25 Feb 2019 09:40:55 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gyCkh-0008Un-UW for pgsql-hackers@postgresql.org; Mon, 25 Feb 2019 09:40:54 +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 x1P9eR2T023819; Mon, 25 Feb 2019 18:40:27 +0900 Received: from vc2.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc2.ecl.ntt.co.jp (Postfix) with ESMTP id 6A6D96391A6; Mon, 25 Feb 2019 18:40:27 +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 5EF2A639228; Mon, 25 Feb 2019 18:40:27 +0900 (JST) Received: from [IPv6:::1] (unknown [129.60.241.75]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 57DDE400714; Mon, 25 Feb 2019 18:40:27 +0900 (JST) Message-ID: <5C73B7FB.2010309@lab.ntt.co.jp> Date: Mon, 25 Feb 2019 18:40:11 +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> <5C6D474F.5010703@lab.ntt.co.jp> <30939.1550848901@localhost> In-Reply-To: <30939.1550848901@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/02/23 0:21), Antonin Houska wrote: > Etsuro Fujita wrote: >>> (2019/02/08 2:04), Antonin Houska wrote: >>>> * regression tests: I think test(s) should be added for queries that have >>>> ORDER BY clause but do not have GROUP BY (and also no LIMIT / OFFSET) >>>> clause. I haven't noticed such tests. >> I noticed that such queries would be processed by what we already have for >> sort pushdown (ie, add_paths_with_pathkeys_for_rel()). I might be missing >> something, though. > > What about an ORDER BY expression that contains multiple Var nodes? For > example > > SELECT * FROM foo ORDER BY x + y; > > I think the base relation should not be able to generate paths with the > corresponding pathkeys, since its target should (besides PlaceHolderVars, > which should not appear in the plan of this simple query at all) only emit > individual Vars. Actually, add_paths_with_pathkeys_for_rel() generates such pre-sorted paths for the base relation, as shown in the below example using HEAD without the patchset proposed in this thread: postgres=# explain verbose select a+b from ft1 order by a+b; QUERY PLAN -------------------------------------------------------------------------- Foreign Scan on public.ft1 (cost=100.00..200.32 rows=2560 width=4) Output: (a + b) Remote SQL: SELECT a, b FROM public.t1 ORDER BY (a + b) ASC NULLS LAST (3 rows) I think it is OK for that function to generate such paths, as tlists for such paths would be adjusted in apply_scanjoin_target_to_paths(), by doing create_projection_path() to them. Conversely, it appears that add_foreign_ordered_paths() added by the patchset would generate such pre-sorted paths *redundantly* when the input_rel is the final scan/join relation. Will look into that. Best regards, Etsuro Fujita