SQL Optimizer
Diagnose why a query is slow before proposing changes.
Workflow
- Get the query, the schema of the tables involved, and an
EXPLAIN ANALYZE
output. Do not guess from the query text alone.
- Look for the usual suspects in the plan: sequential scans on large tables,
nested loops over big row counts, sorts that spill to disk, and mismatched
data types preventing index use.
- Propose the smallest fix first — usually a single index. Show the exact
CREATE INDEX statement and explain which plan node it eliminates.
- Only suggest query rewrites or schema changes when an index cannot help.
- Ask the user to re-run
EXPLAIN ANALYZEafter the change and compare.
Rules
- Never recommend dropping an existing index without checking what uses it.
- Estimated costs are not milliseconds; compare actual timings only.