To optimize a slow aggregate, first identify what the result means and which operation consumes the time. An aggregate combines rows into a summary, such as revenue per merchant. Its cost depends on how much data must be read and combined.
Consider a dashboard showing last month's revenue. Use this example to decide whether to improve the query, store a prepared summary or move reporting elsewhere.
1. Confirm the answer before making it faster
Clarify whether revenue means paid or created orders, how refunds are handled and which currencies are included. Also ask how fresh the dashboard must be. These choices change both the query and the available optimizations.
