SQL Query Performance Checklist: 10 Steps to Diagnose Slow Queries
By Sharon Ben-Moshe · October 13, 2026 · 2 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
A 10-step checklist to diagnose and optimize slow SQL queries. Learn how to spot table scans, non-SARGable WHERE predicates, and unindexed joins.
Quick answer
Diagnosing slow SQL queries follows a systematic 10-step process: 1) Run EXPLAIN ANALYZE, 2) Check for sequential/table scans on large tables, 3) Verify that WHERE clauses are SARGable (no functions wrapping indexed columns), 4) Index foreign key join columns, 5) Replace SELECT * with explicit projections, 6) Check table statistics (ANALYZE), 7) Look for nested loop Cartesian joins, 8) Use EXISTS instead of IN for subqueries, 9) Bound unbounded LIMIT/OFFSET queries, and 10) Monitor memory spills to disk.
FAQs
What does SARGable mean in SQL?
SARGable stands for 'Search Argument Able'. A query predicate is SARGable when the database engine can directly traverse a B-Tree index (Index Seek/Scan). Wrapping columns in functions like `WHERE YEAR(created_at) = 2026` makes predicates non-SARGable.
Why is SELECT * bad for query performance?
SELECT * prevents the query optimizer from using covering indexes, forces the engine to read large unused text/JSON columns from disk into memory, and increases network transmission overhead.
How do outdated table statistics slow queries down?
Query optimizers choose execution plans (Hash Join vs Nested Loop vs Merge Join) based on table statistics. If statistics are stale, the engine may assume a table has 100 rows when it actually has 10 million, choosing catastrophic plans.
What is an index seek vs index scan?
An Index Seek navigates the B-Tree directly to the target rows in O(log N) time. An Index Scan traverses the entire index leaf sequence in O(N) time. Seeks are significantly faster for selective filters.
Keep reading
SQL Query Optimization and Tuning: The End-to-End Practitioner's Guide
By Sharon Ben-Moshe · Oct 13, 2026
The definitive guide to SQL query optimization. Master EXPLAIN execution plans, SARGable predicates, covering indexes, and keyset cursor pagination.
Read postHow SQL Query Engines Actually Execute Queries: The Complete Lifecycle
By Sharon Ben-Moshe · Oct 13, 2026
Journey through the SQL query lifecycle. Explore lexical parsing, Abstract Syntax Trees, logical optimization, Cost-Based Optimizers, and Volcano execution.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.