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 1gzg8R-0006cl-V1 for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Mar 2019 11:15:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gzg8Q-0008TV-Lu for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Mar 2019 11:15:22 +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 1gzg8Q-0008TO-AC for pgsql-hackers@lists.postgresql.org; Fri, 01 Mar 2019 11:15:22 +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 1gzg8I-00077R-8H for pgsql-hackers@postgresql.org; Fri, 01 Mar 2019 11:15:20 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id A42D9A1119; Fri, 1 Mar 2019 12:15:06 +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=1551438904; 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=uaxrG9FMylty2jjSQR/hJVsBFeHxSP1prmx8LzcwaBM=; b=pgbcZqrXlaCwrwSYjxp7jcyb7tMLSnpRv7xmDZgWEe+Hk2PkU3TjITCjfDFdklq4IElOG9 XKEXFqfyblnLgRjt9ZFSaVU9GwChroUbfcMq0XMlJIT1G2q0pcDsX6naQ6i2X+/XTxfKEs ftkr7O6qdgXoujE7e92VXw+GL4eFjLmD+q9XqGQLVhCgcUHUhhbfnG2V2MHAYkQAuX5HR9 LBA891+HUPJX4+kUBngd+sabr/gK3VSij+LG7NfQQu7ZPdvzdQ0cisc8b4chefnvt8eoam GWNUpwvx2uGbAHuS7Ad13Xx9OiCWCyhpEJXxFhnmgdiuOwmHkSk/OXxQhQaskA== Received: from smtp1.mailbox.org ([80.241.60.240]) by gerste.heinlein-support.de (gerste.heinlein-support.de [91.198.250.173]) (amavisd-new, port 10030) with ESMTP id KS0TksTdnn36; Fri, 1 Mar 2019 12:14:58 +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: <5C73B7FB.2010309@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> <5C6D474F.5010703@lab.ntt.co.jp> <30939.1550848901@localhost> <5C73B7FB.2010309@lab.ntt.co.jp> Comments: In-reply-to Etsuro Fujita message dated "Mon, 25 Feb 2019 18:40:11 +0900." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7519.1551439018.1@localhost> Content-Transfer-Encoding: quoted-printable Date: Fri, 01 Mar 2019 12:16:58 +0100 Message-ID: <7520.1551439018@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Etsuro Fujita wrote: > (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 tha= t have > >>>> ORDER BY clause but do not have GROUP BY (and also no LIMIT / OFFSE= T) > >>>> clause. I haven't noticed such tests. > = > >> I noticed that such queries would be processed by what we already hav= e for > >> sort pushdown (ie, add_paths_with_pathkeys_for_rel()). I might be mi= ssing > >> something, though. > > > > What about an ORDER BY expression that contains multiple Var nodes? Fo= r > > example > > > > SELECT * FROM foo ORDER BY x + y; > > > > I think the base relation should not be able to generate paths with th= e > > corresponding pathkeys, since its target should (besides PlaceHolderVa= rs, > > 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 pa= ths > for the base relation, as shown in the below example using HEAD without = the > patchset proposed in this thread: > = > postgres=3D# explain verbose select a+b from ft1 order by a+b; > QUERY PLAN > ------------------------------------------------------------------------= -- > Foreign Scan on public.ft1 (cost=3D100.00..200.32 rows=3D2560 width=3D= 4) > Output: (a + b) > Remote SQL: SELECT a, b FROM public.t1 ORDER BY (a + b) ASC NULLS LAS= T > (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. I've just checked it. The FDW constructs the (a + b) expression for the OR= DER BY clause on its own. It only needs to find the input vars in the relation target. > Conversely, it appears that add_foreign_ordered_paths() added by the pat= chset > would generate such pre-sorted paths *redundantly* when the input_rel is= the > final scan/join relation. Will look into that. Currently I have no idea how to check the plan created by FDW at the UPPERREL_ORDERED stage, except for removing the sort from the UPPERREL_GROUP_AGG stage as I proposed here: https://www.postgresql.org/message-id/11807.1549564431%40localhost -- = Antonin Houska https://www.cybertec-postgresql.com