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 1fuyFX-0004Il-93 for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Aug 2018 11:02:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fuyFU-0004Cc-R2 for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Aug 2018 11:02:56 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fuyFU-0004CU-HB for pgsql-bugs@lists.postgresql.org; Wed, 29 Aug 2018 11:02:56 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fuyFQ-0001tU-Pa; Wed, 29 Aug 2018 11:02:54 +0000 Received: from [192.168.127.1] (port=32290 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1fuyFM-0009wS-3B; Wed, 29 Aug 2018 11:02:48 +0000 Received: from [127.0.0.1] (port=52782 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1fuyFL-000KLf-AG; Wed, 29 Aug 2018 11:02:47 +0000 From: Andrew Gierth To: Ashutosh Bapat Cc: pgsql-bugs@lists.postgresql.org, maxim.boguk@gmail.com, rhaas@postgresql.org Subject: Re: BUG #15352: postgresql FDW error "ERROR: ORDER BY position 0 is not in select list" In-Reply-To: (Ashutosh Bapat's message of "Wed, 29 Aug 2018 14:25:06 +0530") Message-ID: <87mut5xye8.fsf@news-spur.riddles.org.uk> References: <153518420278.1478.14875560810251994661@wrigleys.postgresql.org> <87efemzw0v.fsf@news-spur.riddles.org.uk> <87a7paz8b1.fsf@news-spur.riddles.org.uk> <87r2iiy3if.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Wed, 29 Aug 2018 12:02:46 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Ashutosh" == Ashutosh Bapat writes: Andrew> It seems obviously wrong that a constant pathkey with no actual Andrew> reference to the foreign table should be being pushed down, so Andrew> so far I suspect that get_useful_pathkeys_for_relation isn't Andrew> being selective enough about what is "useful". In this context Andrew> I find it suspicious that find_em_expr_for_rel will return an Andrew> expr with no vars as being "for" every rel, since it's just Andrew> looking for a subset. Ashutosh> Sorry for replying late. I am not able to understand why it's Ashutosh> wrong to push a constant or for the matter any shippable Ashutosh> expression which doesn't refer to the foreign table/s (for Ashutosh> that matter any tables) under consideration down to the Ashutosh> foreign server. Well, it's certainly pointless. But the failure in this case is specifically about pushing down an _integer_ constant, because the deparse code for pushing down an ORDER BY does not understand that integer literals in ORDER BY clauses are a special case. Ashutosh> The context in the original mail doesn't help. I haven't Ashutosh> checked the original thread on bugs mailing list. I agree Ashutosh> that ordering by such an expression is useless, but if we are Ashutosh> getting that done from a foreign server, what's the harm? But Ashutosh> by not doing it we might be loosing some optimization since Ashutosh> postgres_fdw pushes all or none of pathkeys. I'm pretty sure that constant (hence redundant) clauses have been removed from pathkeys before postgres_fdw will see them. The problem only occurs because postgres_fdw tries inventing _new_ pathkeys for possible orderings from eclasses (in order to try for mergejoin opportunities) in addition to using the requested pathkeys, and it's clearly pointless to do that with constants. -- Andrew (irc:RhodiumToad)