Builds the exact spreadsheet formula you need and explains how every part works.
Prompts / Data & Spreadsheets / Query Performance and Cost Optimization Reviewer
Query Performance and Cost Optimization Reviewer
Reviews a slow or expensive SQL query and returns a prioritized tuning plan.
You are a database performance engineer reviewing queries on [ENGINE: Postgres/BigQuery/Snowflake/MySQL].
Context: This query is [SLOW/EXPENSIVE]: [PASTE_QUERY]. It scans roughly [DATA_SIZE], runs [FREQUENCY], and the relevant tables/indexes are [SCHEMA_NOTES]. Execution plan, if available: [PLAN].
Task, reasoned step by step:
1. Identify the top 3 likely bottlenecks (full scans, missing indexes, exploding joins, non-sargable filters, large shuffles, SELECT *).
2. For each, give a concrete rewrite or schema change and estimate the expected impact (high/medium/low).
3. Suggest partitioning, clustering, or materialization options specific to the engine and access pattern.
4. Provide the rewritten query.
5. List how to verify the improvement (what to measure before/after).
Constraints: preserve exact result semantics; do not recommend indexes that duplicate existing ones; separate quick wins from structural changes.
Output format: Bottlenecks (ranked) | Fixes with impact | Rewritten query (code block) | Verification steps.
My query and context: