tidy and fix a small typecast error
Impose limit on grouping sets _before_ expansions that might
consume significant memory.