As described by Dag Wanvik here, using a ROLLUP-style GROUP BY query as a sub-query of
a larger query causes the query execution logic to be confused about the nullability of the columns
in the subquery:
Fundamentally, the ROLLUP feature can cause NULL values to be returned in non-NULL-able
columns, which is a troubling behavior.
I haven't cataloged the complete symptoms of this problem, but it is definitely
true that in queries such as those described by Dag:
select cast(x as varchar(2)),y,z from (select c,c2,sum from t group by rollup (c,c2)) t(x,y,z)
the result set metadata for the top-level result set will show that the columns are
not nullable, yet they contain NULL values.
Perhaps it would be adequate to have the query compiler detect when a ROLLUP
query is being performed, and force the nullability of the columns to be set, and
then ensure that this nullability is propagated to the final result set columns.