원클릭으로
debug-slow-queries
// Diagnoses and fixes slow database queries using explain plans, statistics, and targeted indexes or rewrites. Use when an endpoint is slow, a query regresses, cpu spikes, or timeouts appear.
// Diagnoses and fixes slow database queries using explain plans, statistics, and targeted indexes or rewrites. Use when an endpoint is slow, a query regresses, cpu spikes, or timeouts appear.
Audits database data quality (nulls, duplicates, orphans, invalid ranges) and produces a short findings report with remediation queries. Use when debugging data issues, validating migrations, or verifying analytics correctness.
Inspects database schema and metadata (tables, columns, indexes, constraints, relationships). Use when exploring an unfamiliar database, writing joins, debugging query behavior, or documenting schema.
Plans and executes safe database migrations with low-downtime patterns, verification, and rollback. Use when changing schema, backfilling data, adding constraints, or creating indexes in production.
| name | debug-slow-queries |
| description | Diagnoses and fixes slow database queries using explain plans, statistics, and targeted indexes or rewrites. Use when an endpoint is slow, a query regresses, cpu spikes, or timeouts appear. |
Goal: go from "slow" to a verified fix with minimal risk.
get plan + timing:
EXPLAIN (ANALYZE, BUFFERS, VERBOSE) <query>;
check table stats freshness:
SELECT relname, n_live_tup, last_analyze, last_autoanalyze
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC;
see indexes:
SELECT tablename, indexname, indexdef
FROM pg_indexes
WHERE schemaname = 'public' AND tablename = 'your_table';
safe index creation:
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_name ON your_table (col1, col2);
get plan:
EXPLAIN <query>;
get runtime plan details (mysql 8):
EXPLAIN ANALYZE <query>;
see indexes:
SHOW INDEX FROM your_table;
get plan:
EXPLAIN QUERY PLAN <query>;
select *
offset pagination at scale
Use this checklist:
## slow query report
### symptom
- endpoint/job:
- p50/p95:
- query:
### evidence
- explain plan notes:
- row counts:
- indexes involved:
### root cause
- primary bottleneck:
- why it happens:
### fix
- change:
- risk:
- rollback:
### verification
- before:
- after:
- correctness checks: