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 1fvg59-0000ym-1o for pgsql-bugs@arkaria.postgresql.org; Fri, 31 Aug 2018 09:51:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fvg56-0004Kl-U5 for pgsql-bugs@arkaria.postgresql.org; Fri, 31 Aug 2018 09:51:08 +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 1fvg56-0004Ke-Kv for pgsql-bugs@lists.postgresql.org; Fri, 31 Aug 2018 09:51:08 +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 1fvg53-00068L-Jx; Fri, 31 Aug 2018 09:51:07 +0000 Received: from [192.168.127.1] (port=56371 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 1fvg50-000Ems-Ll; Fri, 31 Aug 2018 09:51:02 +0000 Received: from [127.0.0.1] (port=37062 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1fvg4z-000CY1-UW; Fri, 31 Aug 2018 09:51:02 +0000 From: Andrew Gierth To: Ashutosh Bapat Cc: pgsql-bugs@lists.postgresql.org, 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 "Fri, 31 Aug 2018 11:58:26 +0530") Message-ID: <87pnxyx6kf.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> <87mut5xye8.fsf@news-spur.riddles.org.uk> <87efegxn6b.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Fri, 31 Aug 2018 10:51:00 +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: Ashutosh> Looking at deparseSortGroupClause() this issue looks to be Ashutosh> fixed in HEAD. Either the version where bug was found doesn't Ashutosh> have this fix or somehow the fix isn't working. You're misreading the code. The OP's example clearly demonstrates the bug when tested with HEAD prior to bf2d0462c or with bf2d0462c reverted. As the code stands, it _cannot_ use deparseSortGroupClause for generating EXPLAINs for pathkeys that are chosen by postgres_fdw, because deparseSortGroupClause wants a tlist, not a plain list of expressions. (Perhaps you haven't realized that without the additional check, when remote estimates are enabled we end up sending EXPLAIN commands to the remote for paths that cannot possibly be of any use in the query? Round-trips to the remote are not free.) >> How do you think that could happen, given that redundant pathkeys >> are already removed? Ashutosh> I don't have exact answer. Then you should find out. Ashutosh> But deparseSortGroupClause() has code to deparse constants in Ashutosh> GROUP BY indicates that we do encounter such pathkeys Ashutosh> somewhere. GROUP BY isn't based on pathkeys (for one thing, grouping columns might not be sortable). Ashutosh> I am thinking about ORDER BY being pushed down for GROUP BY. Perhaps you should take a look at how the pathkeys for that case are generated. -- Andrew (irc:RhodiumToad)