Problem Statement
When can a stream (ordered) aggregate beat a hash aggregate?
Explanation
With input sorted by group keys, a streaming aggregate walks once and emits groups as they change. It avoids building a hash table and reduces memory.
Hash aggregate is great for large, unsorted sets but may spill if memory is tight.
Code Solution
SolutionRead Only
SELECT customer_id, SUM(total) FROM orders GROUP BY customer_id; -- index on (customer_id) enables stream aggregate
Practice Sets
This question appears in the following practice sets:
