Query rewrite techniques are provided for rewriting an aggregate query
with multiple groupings using multiple summary tables. The rewrite is
accomplished by expanding the aggregate query into an equivalent UNION
ALL query with multiple subqueries, each containing a single grouping.
One or more of the subqueries is then rewritten to reference a summary
table. Thus, a grouping of an aggregate query is derived by executing a
subquery that either scans the summary table for the grouping, like in
the exact-match mode, or by performing a roll-up operation, like in the
roll-up mode. In addition, if the grouping of some of the subqueries
cannot be derived from a summary table, subqueries are combined into
another subquery that computes groupings from the base tables of the
aggregate query.