Explain the process of optimizing a slow-running SQL query at Pinterest.
Using the provided PostgreSQL schema, explain how you would investigate and improve the query, then provide the optimized query. Address execution plans, filtering, joins, aggregation, and relevant indexing decisions.
Output
- One row per qualifying creator with
creator_id, creator_name, and qualifying_saves
- Include only published pins with saves from January 2025 and at least two qualifying saves
- Order by
qualifying_saves descending, then creator_id ascending