All articles

Performance

Slow Query Optimization: Fix the Plans, Not the Symptom

Sep 16, 2026 slow queries · indexes · query plans · mysql · postgresql

Why the slowest queries in production are rarely the ones you think, and how to rank work by total latency contribution.

Most teams optimize the queries users complain about. The problem: user-visible slowness and total latency cost are different rankings. The query that made one customer angry yesterday is not necessarily the one eating 60% of your database time every minute.

Total-cost thinking is the foundation of every slow-query optimization engagement we run.

Aggregate before you analyze

On MySQL, digest tables give you statement templates with aggregated timing; on PostgreSQL, pg_stat_statements does the same. Sort by total time, not mean time. The top of that list is where engineering hours earn their keep.

EXPLAIN ANALYZE is the only honest witness

Plans change with data volume, statistics, and parameters. A plan comparison before and after each change — actual rows, actual time, buffer usage — is the only record that proves an optimization worked. Keep the deltas; they become your performance history.

Tags

slow queries indexes query plans mysql postgresql

Related articles

Work with Burj

Your database deserves engineering, not guesswork.

Tell us what is slow — CPU, queries, migrations, or cost — and we will scope the smallest safe fix.

Plan an engagement