This iterator abstracts the operation that gets an array of groupby keys for the next grouping set from the full set of grouping sets and makes such logic re-usable in several places. Actually, a more generic iterator could be defined to hide the differences between presence and absence of grouping sets, which would make the code change simpler and cleaner. But for performance consideration, separate handling of presence and absence of grouping sets was chosen.