Re: BUG #14890: Error grouping by same column twice using FDW
Jeevan Chalke <jeevan.chalke@enterprisedb.com>
From: Jeevan Chalke <jeevan.chalke@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: sean.johnston@edgeintelligence.com, Postgres-Bugs <pgsql-bugs@postgresql.org>,
Robert Haas <robertmhaas@gmail.com>, Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Date: 2017-11-09T11:59:12Z
Lists: pgsql-bugs
Attachments
- fix_multiple_sortgroupref_labels.patch (text/x-patch) patch
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
Commits
-
Fix postgres_fdw to cope with duplicate GROUP BY entries.
- e9f2703ab7b2 11.0 landed
- 67854bc59a8b 10.2 landed
-
postgres_fdw: Push down aggregates to remote servers.
- 7012b132d07c 10.0 cited