Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eDEJ1-0001Qi-RR for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Nov 2017 18:45:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1eDEJ1-0004lj-2y for pgsql-bugs@arkaria.postgresql.org; Fri, 10 Nov 2017 18:45:31 +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.84_2) (envelope-from ) id 1eDEIH-0003QV-Ep for pgsql-bugs@postgresql.org; Fri, 10 Nov 2017 18:44:45 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eDEIE-00029s-QJ for pgsql-bugs@postgresql.org; Fri, 10 Nov 2017 18:44:44 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vAAIia0p009633; Fri, 10 Nov 2017 13:44:36 -0500 From: Tom Lane To: Ashutosh Bapat cc: Jeevan Chalke , sean.johnston@edgeintelligence.com, Postgres-Bugs , Robert Haas Subject: Re: BUG #14890: Error grouping by same column twice using FDW In-reply-to: References: <20171107134948.1508.94783@wrigleys.postgresql.org> <10660.1510093781@sss.pgh.pa.us> Comments: In-reply-to Ashutosh Bapat message dated "Fri, 10 Nov 2017 18:14:29 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9631.1510339476.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 10 Nov 2017 13:44:36 -0500 Message-ID: <9632.1510339476@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Ashutosh Bapat writes: > On Thu, Nov 9, 2017 at 5:29 PM, Jeevan Chalke > wrote: >> + Remote SQL: SELECT c2, c2 FROM "S 1"."T 1" WHERE ((c2 =3D 6)) GROUP = BY c2, c2 > GROUP BY 1, 2 is changed to GROUP BY c2, c2 which is technically wrong. T= he > remote planner will think that both the GROUP BY entries refer to one of = the > (possibly the first) entry in the SELECT clause. That's not what really i= t is. Yeah. I'm inclined to think that part of what needs to happen here is for postgres_fdw to change over to always emitting GROUP BY column-number, so that the grouping columns are clearly matched up with the tlist entries it's considering, and the remote parser is certain to build ressortgrouprefs that match what we thought was happening locally. As you say, we can probably get away without that as long as we don't push mutable grouping expressions ... but just because we think a grouping expression is immutable at our end doesn't necessarily mean that it is at the far end. Also, in view of the (as yet unfixed) bug discussed in https://www.postgresql.org/message-id/flat/7dbdcf5c-b5a6-ef89-4958-da212fe1= 0176@iki.fi there's no hope of extending postgres_fdw to push GROUPING SETS correctly unless it is able to distinguish textually-equal grouping columns. > May be we were not explaining this correctly earlier. The sortgrouprefs of > GROUP BY clause can not be different between those two tlists. The differ= ence > is really the absence of ORDER BY entries. May be we should add some tests > where there some entries common between ORDER BY and GROUP BY. As I alluded to upthread, I suspect that dropping ORDER BY markings from the tlist is likely to break some cases (that is, the planner may expect the output of the foreign scan to include those columns). If this isn't fully exercised by the existing tests then we definitely need more tests. regards, tom lane --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs