]> granicus.if.org Git - postgresql/blobdiff - src/backend/optimizer/util/pathnode.c
Make the behavior of HAVING without GROUP BY conform to the SQL spec.
[postgresql] / src / backend / optimizer / util / pathnode.c
index 64c802805a75e4a0a049cbcff7fd055c26435ebc..f20c95299f34d8a8f46aacb7f6e25f4ac9cd5ca1 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.111 2004/12/31 22:00:23 pgsql Exp $
+ *       $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.112 2005/03/10 23:21:22 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -797,6 +797,15 @@ is_distinct_query(Query *query)
                if (!gl)                                /* got to the end? */
                        return true;
        }
+       else
+       {
+               /*
+                * If we have no GROUP BY, but do have aggregates or HAVING, then
+                * the result is at most one row so it's surely unique.
+                */
+               if (query->hasAggs || query->havingQual)
+                       return true;
+       }
 
        /*
         * XXX Are there any other cases in which we can easily see the result