|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
|
25 | 25 | #include"optimizer/pathnode.h"
|
26 | 26 | #include"optimizer/paths.h"
|
27 | 27 | #include"optimizer/restrictinfo.h"
|
| 28 | +#include"optimizer/tlist.h" |
28 | 29 | #include"parser/parse_expr.h"
|
29 | 30 | #include"parser/parse_oper.h"
|
30 | 31 | #include"parser/parsetree.h"
|
@@ -688,6 +689,28 @@ is_distinct_query(Query *query)
|
688 | 689 | return true;
|
689 | 690 | }
|
690 | 691 |
|
| 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 | + |
691 | 714 | /*
|
692 | 715 | * XXX Are there any other cases in which we can easily see the result
|
693 | 716 | * must be distinct?
|
|