Re: [BUGS] BUG #14890: Error grouping by same column twice using FDW - Mailing list pgsql-bugs

From Jeevan Chalke
Subject Re: [BUGS] BUG #14890: Error grouping by same column twice using FDW
Date
Msg-id CAM2+6=X3CwoJ6LE3AGrDmBh1-zhJVd2WAPGKk0zLqDMfhJYOhQ@mail.gmail.com
Whole thread Raw
In response to Re: [BUGS] BUG #14890: Error grouping by same column twice using FDW  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [BUGS] BUG #14890: Error grouping by same column twice using FDW  (Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>)
List pgsql-bugs


On Wed, Nov 8, 2017 at 3:59 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
sean.johnston@edgeintelligence.com writes:
> select col1, col1 from loop_tbl group by 1, 2;
> psql:t.sql:7: ERROR:  targetlist item has multiple sortgroupref labels

This is the fault of commit 7012b132d ("Push down aggregates to remote
servers"), which imagined that postgres_fdw can use
apply_pathtarget_labeling_to_tlist() for situations well beyond that
function's limited abilities.  I kinda suspect that foreign_grouping_ok()
has got more bugs than this with complicated sortgroupref situations, too;
its willingness to scribble on the sortgrouprefs doesn't look like a great
idea to me.

In the attached patch, I have removed apply_pathtarget_labeling_to_tlist()
call. Since we are anyways checking that whether the GROUP BY expression is
entirely present in a target list or not, we can safely create a tle for that
GROUP BY expression and append that to the new targetlist by making sure that
its sortgroupref is also transferred, eliminating the need for relabeling
afterwords.

Now with these changes i.e. as we have moved setting sortgroupref for tle
inside the if block itself, we don't have to reset the sortgroupref for any
ORDER BY expression. That code is removed. This also eliminated the need for
copying the pathtarget.

Please have a look at the changes and let me know if I missed any.

Thanks
 

                        regards, tom lane



--
Jeevan Chalke
Technical Architect, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Attachment

pgsql-bugs by date:

Previous
From: Amit Langote
Date:
Subject: Re: [BUGS] BUG #14866: The generated constraint in the typed tablecauses the server to crash
Next
From: minfrin@sharp.fm
Date:
Subject: [BUGS] BUG #14893: libpq SSL ClientHello too long,no option to set ciphers or affect cipher list length