]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix an Assert that turns out to be reachable after all.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 Apr 2012 15:59:17 +0000 (11:59 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 9 Apr 2012 15:59:17 +0000 (11:59 -0400)
estimate_num_groups() gets unhappy with
create table empty();
select * from empty except select * from empty e2;
I can't see any actual use-case for such a query (and the table is illegal
per SQL spec), but it seems like a good idea that it not cause an assert
failure.

src/backend/utils/adt/selfuncs.c

index 256a07257286e6e7f19076861d089f28992ccadb..1455116ce9debe0a094a0356612b0c4e7afed049 100644 (file)
@@ -2616,8 +2616,13 @@ estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows)
        double          numdistinct;
        ListCell   *l;
 
-       /* We should not be called unless query has GROUP BY (or DISTINCT) */
-       Assert(groupExprs != NIL);
+       /*
+        * If no grouping columns, there's exactly one group.  (This can't happen
+        * for normal cases with GROUP BY or DISTINCT, but it is possible for
+        * corner cases with set operations.)
+        */
+       if (groupExprs == NIL)
+               return 1.0;
 
        /*
         * Count groups derived from boolean grouping expressions.  For other