Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite9f2703

Browse files
committed
Fix postgres_fdw to cope with duplicate GROUP BY entries.
Commit7012b13, which added the ability to push down aggregates andgrouping to the remote server, wasn't careful to ensure that the remoteserver would have the same idea we do about which columns are the groupingcolumns, in cases where there are textually identical GROUP BY expressions.Such cases typically led to "targetlist item has multiple sortgroupreflabels" errors.To fix this reliably, switch over to using "GROUP BY column-number" syntaxrather than "GROUP BY expression" in transmitted queries, and adjustforeign_grouping_ok() to be more careful about duplicating the sortgroupreflabeling of the local pathtarget.Per bug #14890 from Sean Johnston. Back-patch to v10 where the buggy codewas introduced.Jeevan Chalke, reviewed by Ashutosh BapatDiscussion:https://postgr.es/m/20171107134948.1508.94783@wrigleys.postgresql.org
1 parent680d540 commite9f2703

File tree

4 files changed

+150
-119
lines changed

4 files changed

+150
-119
lines changed

‎contrib/postgres_fdw/deparse.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void appendGroupByClause(List *tlist, deparse_expr_cxt *context);
178178
staticvoidappendAggOrderBy(List*orderList,List*targetList,
179179
deparse_expr_cxt*context);
180180
staticvoidappendFunctionName(Oidfuncid,deparse_expr_cxt*context);
181-
staticNode*deparseSortGroupClause(Indexref,List*tlist,
181+
staticNode*deparseSortGroupClause(Indexref,List*tlist,boolforce_colno,
182182
deparse_expr_cxt*context);
183183

184184
/*
@@ -2853,7 +2853,7 @@ appendAggOrderBy(List *orderList, List *targetList, deparse_expr_cxt *context)
28532853
first= false;
28542854

28552855
sortexpr=deparseSortGroupClause(srt->tleSortGroupRef,targetList,
2856-
context);
2856+
false,context);
28572857
sortcoltype=exprType(sortexpr);
28582858
/* See whether operator is default < or > for datatype */
28592859
typentry=lookup_type_cache(sortcoltype,
@@ -2960,7 +2960,7 @@ appendGroupByClause(List *tlist, deparse_expr_cxt *context)
29602960
appendStringInfoString(buf,", ");
29612961
first= false;
29622962

2963-
deparseSortGroupClause(grp->tleSortGroupRef,tlist,context);
2963+
deparseSortGroupClause(grp->tleSortGroupRef,tlist,true,context);
29642964
}
29652965
}
29662966

@@ -3047,7 +3047,8 @@ appendFunctionName(Oid funcid, deparse_expr_cxt *context)
30473047
* need not find it again.
30483048
*/
30493049
staticNode*
3050-
deparseSortGroupClause(Indexref,List*tlist,deparse_expr_cxt*context)
3050+
deparseSortGroupClause(Indexref,List*tlist,boolforce_colno,
3051+
deparse_expr_cxt*context)
30513052
{
30523053
StringInfobuf=context->buf;
30533054
TargetEntry*tle;
@@ -3056,7 +3057,13 @@ deparseSortGroupClause(Index ref, List *tlist, deparse_expr_cxt *context)
30563057
tle=get_sortgroupref_tle(ref,tlist);
30573058
expr=tle->expr;
30583059

3059-
if (expr&&IsA(expr,Const))
3060+
if (force_colno)
3061+
{
3062+
/* Use column-number form when requested by caller. */
3063+
Assert(!tle->resjunk);
3064+
appendStringInfo(buf,"%d",tle->resno);
3065+
}
3066+
elseif (expr&&IsA(expr,Const))
30603067
{
30613068
/*
30623069
* Force a typecast here so that we don't emit something like "GROUP

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp