// troubleshooting guides

SQL performance troubleshooting

A slow query is fixed with evidence: the waits, the plan and the statement history your database already records. Each guide below works through that evidence for one engine or one symptom, with the commands to run and an ordered checklist at the end.

By database engine

An engine guide covers the whole loop on that engine: rank the statements that cost the most, read the execution plan, and fix what it shows. It uses the engine's own DMVs, pg_stat views, EXPLAIN variants and system views.

SQL Server

Symptom guides with SQL Server commands

PostgreSQL

Symptom guides with PostgreSQL commands

MySQL

Symptom guides with MySQL commands

SQLite

Symptom guides with SQLite commands

Oracle

Symptom guides with Oracle commands

By symptom

Start from what you see: one query that is always slow, a query that used to be fast, CPU pegged, sessions queueing behind locks, an index the planner ignores, or reads going to disk because the cache is too small.

By what the plan shows

Start from the execution plan: one guide per thing a plan can tell you, with how to confirm it and what to change. The query plan viewer links each of its findings to the matching guide.

  • Reading the plan

    Capture a plan with run-time numbers and learn what each kind of operator does.

  • Indexes and access paths

    The plan reads far more rows than it returns, or goes back to the table for every row it finds.

  • Row estimates and statistics

    The optimizer planned for a different number of rows than it got.

  • Sorts, memory and temp space

    A sort, hash or temporary table is doing the work an index or more memory would avoid.

  • Joins and subqueries

    The join order or join method multiplies the work, or a subquery runs once per row.

  • Parallelism, functions and compile time

    The plan ran on fewer threads than it could, calls a function per row, or spends its time compiling.

// fix it where the query lives

Run these queries in SQLly

SQLly is a native SQL workbench for macOS, Windows and Linux. The query plan viewer and formatter these guides link to are built into its editor.