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

Commit03e2a47

Browse files
committed
Teach is_distinct_query to recognize that GROUP BY forces a subquery's
output to be distinct, if all the GROUP BY columns appear in the output.Per suggestion from Dennis Haney.
1 parent49032ca commit03e2a47

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

‎src/backend/optimizer/util/pathnode.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.101 2004/02/03 17:34:03 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.102 2004/03/02 16:42:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -25,6 +25,7 @@
2525
#include"optimizer/pathnode.h"
2626
#include"optimizer/paths.h"
2727
#include"optimizer/restrictinfo.h"
28+
#include"optimizer/tlist.h"
2829
#include"parser/parse_expr.h"
2930
#include"parser/parse_oper.h"
3031
#include"parser/parsetree.h"
@@ -688,6 +689,28 @@ is_distinct_query(Query *query)
688689
return true;
689690
}
690691

692+
/*
693+
* GROUP BY guarantees uniqueness if all the grouped columns appear in
694+
* the output. In our implementation this means checking they are non
695+
* resjunk columns.
696+
*/
697+
if (query->groupClause)
698+
{
699+
List*gl;
700+
701+
foreach(gl,query->groupClause)
702+
{
703+
GroupClause*grpcl= (GroupClause*)lfirst(gl);
704+
TargetEntry*tle=get_sortgroupclause_tle(grpcl,
705+
query->targetList);
706+
707+
if (tle->resdom->resjunk)
708+
break;
709+
}
710+
if (!gl)/* got to the end? */
711+
return true;
712+
}
713+
691714
/*
692715
* XXX Are there any other cases in which we can easily see the result
693716
* must be distinct?

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp