How do you approach optimizing slow-running SQL queries and stored procedures in large-scale relational databases?
Using the provided PostgreSQL tables, write an optimized query that identifies active accounts with at least 100 billable usage units during 2025. The query should avoid unnecessary row multiplication and preserve accounts even when plan details are missing.
Output
- One row per qualifying active account with
account_id, account_name, plan_name, and total_billable_units
- Include only accounts with at least 100 billable units during 2025
- Sort by
total_billable_units descending, then account_id ascending