]> granicus.if.org Git - postgresql/commit
Fix postgres_fdw to cope with duplicate GROUP BY entries.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 12 Jan 2018 21:52:49 +0000 (16:52 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 12 Jan 2018 21:52:49 +0000 (16:52 -0500)
commit67854bc59a8b283f02f2a8f0c0095df639bedf06
tree3b9ce91c628b9c9f2d46bec744b13c51319bac8f
parent55e5eb4d97fbe78af9c81d808afbd0d8559fb392
Fix postgres_fdw to cope with duplicate GROUP BY entries.

Commit 7012b132d, which added the ability to push down aggregates and
grouping to the remote server, wasn't careful to ensure that the remote
server would have the same idea we do about which columns are the grouping
columns, in cases where there are textually identical GROUP BY expressions.
Such cases typically led to "targetlist item has multiple sortgroupref
labels" errors.

To fix this reliably, switch over to using "GROUP BY column-number" syntax
rather than "GROUP BY expression" in transmitted queries, and adjust
foreign_grouping_ok() to be more careful about duplicating the sortgroupref
labeling of the local pathtarget.

Per bug #14890 from Sean Johnston.  Back-patch to v10 where the buggy code
was introduced.

Jeevan Chalke, reviewed by Ashutosh Bapat

Discussion: https://postgr.es/m/20171107134948.1508.94783@wrigleys.postgresql.org
contrib/postgres_fdw/deparse.c
contrib/postgres_fdw/expected/postgres_fdw.out
contrib/postgres_fdw/postgres_fdw.c
contrib/postgres_fdw/sql/postgres_fdw.sql