Re: BUG #14890: Error grouping by same column twice using FDW

From: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: sean(dot)johnston(at)edgeintelligence(dot)com, Postgres-Bugs <pgsql-bugs(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Ashutosh Bapat <ashutosh(dot)bapat(at)enterprisedb(dot)com>
Subject: Re: BUG #14890: Error grouping by same column twice using FDW
Date: 2017-11-09 11:59:12
Message-ID: CAM2+6=X3CwoJ6LE3AGrDmBh1-zhJVd2WAPGKk0zLqDMfhJYOhQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Nov 8, 2017 at 3:59 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> sean(dot)johnston(at)edgeintelligence(dot)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 Content-Type Size
fix_multiple_sortgroupref_labels.patch text/x-patch 5.2 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message minfrin 2017-11-09 13:57:18 BUG #14893: libpq SSL ClientHello too long, no option to set ciphers or affect cipher list length
Previous Message Amit Langote 2017-11-09 05:39:33 Re: BUG #14866: The generated constraint in the typed table causes the server to crash