When HASH GROUP BY Is Healthy

Faster than SORT GROUP BY for large aggregations when output order is unnecessary.

When HASH GROUP BY Becomes a Production Bottleneck

Spills heavily to TEMP (direct path write/read temp) when grouping high-cardinality keys with wide columns.

DBMS_XPLAN Tuning Checklist

  • Check OMem vs Used-Tmp to detect TEMP spills.
  • Filter rows with WHERE before grouping instead of filtering post-aggregation with HAVING.

Before (Slow Pattern)

SELECT customer_id, SUM(amount) FROM ledger GROUP BY customer_id HAVING customer_id = 42;

After (Tuned Pattern)

SELECT customer_id, SUM(amount) FROM ledger WHERE customer_id = 42 GROUP BY customer_id;