diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-03-02 16:42:20 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-03-02 16:42:20 +0000 |
commit | 03e2a47e0bf11fd8ec33d0a4b302347c5a765e7e (patch) | |
tree | b919bcef5816544cdf8ee0d02d6072d70fb5a0a3 | |
parent | 49032ca76554e4bdbff5f72f7dced146fb14ef0d (diff) | |
download | postgresql-03e2a47e0bf11fd8ec33d0a4b302347c5a765e7e.tar.gz postgresql-03e2a47e0bf11fd8ec33d0a4b302347c5a765e7e.zip |
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.
-rw-r--r-- | src/backend/optimizer/util/pathnode.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index 549909dfa0a..e4f7cb97d15 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.101 2004/02/03 17:34:03 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.102 2004/03/02 16:42:20 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -25,6 +25,7 @@ #include "optimizer/pathnode.h" #include "optimizer/paths.h" #include "optimizer/restrictinfo.h" +#include "optimizer/tlist.h" #include "parser/parse_expr.h" #include "parser/parse_oper.h" #include "parser/parsetree.h" @@ -689,6 +690,28 @@ is_distinct_query(Query *query) } /* + * GROUP BY guarantees uniqueness if all the grouped columns appear in + * the output. In our implementation this means checking they are non + * resjunk columns. + */ + if (query->groupClause) + { + List *gl; + + foreach(gl, query->groupClause) + { + GroupClause *grpcl = (GroupClause *) lfirst(gl); + TargetEntry *tle = get_sortgroupclause_tle(grpcl, + query->targetList); + + if (tle->resdom->resjunk) + break; + } + if (!gl) /* got to the end? */ + return true; + } + + /* * XXX Are there any other cases in which we can easily see the result * must be distinct? */ |