Sam Mason <sam@xxxxxxxxxxxxx> writes: > I've just noticed that the planner in 8.3.3 doesn't seem to realize the > difference in the result of the following: > GROUP BY col; > GROUP BY col IS NULL; Yeah, estimate_num_groups doesn't have any special knowledge about IS NULL -- it just sees this as "an expression involving col". The general assumption about that is that the expression doesn't reduce the number of groups (think "col + 1" for example). In general I'd rather it overestimated the number of groups than underestimated, so I don't think this heuristic is really wrong. Putting in a special case for IS NULL seems a bit silly, but maybe checking for a boolean result type would cover enough real-world uses to be worth the trouble? Not sure. regards, tom lane