Describe various query optimization techniques you use to improve performance on large datasets.
Demonstrate the techniques by writing a PostgreSQL query that summarizes qualifying opportunity revenue for active accounts during Q1 2025. The query should be suitable for explaining indexing, predicate filtering, pre-aggregation, and execution-plan analysis.
Output
- One row per active account with at least one qualifying opportunity
- Columns:
account_id, account_name, owner_name, total_revenue, and won_opportunities
- Include only positive-amount Closed Won opportunities closed during Q1 2025
- Sort by
total_revenue descending, then account_id ascending, and return at most 10 rows