COUNT, SUM, AVG, MIN, MAX: Performance
Module: Aggregate Functions & Grouping
**Performance Insights:**
• Aggregates typically require scanning all matching rows
• COUNT(*) is highly optimized - often uses index metadata
• Indexes on WHERE clause columns dramatically improve performance
• Multiple aggregates in one query are computed in a single pass (efficient)
COUNT(*) is highly optimized - often uses index metadata
Create indexes on columns used in WHERE clauses with aggregates
Filter with WHERE to reduce rows before aggregation
Multiple aggregates in one query are computed in a single pass
Mixing aggregate and non-aggregate columns without GROUP BY causes errors
Assuming AVG treats NULL as zero (it ignores NULL completely)
Using COUNT(column) when COUNT(*) is needed (or vice versa)
Expecting SUM of all NULL values to return 0 (it returns NULL)
Not using DISTINCT with COUNT when counting unique values