- /*
- * XXX for the moment, take the number of distinct groups as equal to
- * the total input size, i.e., the worst case. This is too
- * conservative, but it's not clear how to get a decent estimate of
- * the true size. One should note as well the propensity of novices
- * to write UNION rather than UNION ALL even when they don't expect
- * any duplicates...
- */
- dNumGroups = apath->rows;
+ if (list_length(cheapest_pathlist) == 1)
+ {
+ Path *path = linitial(cheapest_pathlist);
+
+ /*
+ * In the case where only one union child remains due to the
+ * detection of one or more dummy union children, obtain an
+ * estimate on the surviving child directly.
+ */
+ dNumGroups = estimate_num_groups(root,
+ path->pathtarget->exprs,
+ path->rows,
+ NULL,
+ NULL);
+ }
+ else
+ {
+ /*
+ * Otherwise, for the moment, take the number of distinct groups
+ * as equal to the total input size, i.e., the worst case. This
+ * is too conservative, but it's not clear how to get a decent
+ * estimate of the true size. One should note as well the
+ * propensity of novices to write UNION rather than UNION ALL even
+ * when they don't expect any duplicates...
+ */
+ dNumGroups = apath->rows;
+ }