Hash aggregation operates in two phases. In the first phase, data read
from underlying row source is partitioned on GROUP BY keys with
on-the-fly aggregation. It is determined into which partition an entry
corresponding to the incoming record should be grouped, and whether a
matching entry is already present in the partition, using a hash function
and a hash table built for the partition. For aggregation operations, if
a match is found, then a measure value from the incoming record is
aggregated with a measure value for the entry existing in the partition.
If there is not enough system volatile memory to complete the first
phase, then a partition is selected for storing persistently. Thus, only
one partition at a time is stored persistently, as necessary. In the
second phase, one persistently stored partition is processed at a time,
whereby aggregation of the data in that partition is completed and
results are returned.