← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · ✎ updated 7d
← Back to glossary

EXPLAIN ANALYZE

Database PHP 5.0+ Advanced
debt(d5/e3/b3/t5)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches' (d5). The term's detection_hints.tools list mysql-slow-query-log, percona-toolkit, and laravel-debugbar — these are specialist profiling/debugging tools that identify slow queries lacking EXPLAIN analysis, not default linters or compiler checks.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is straightforward: run EXPLAIN FORMAT=JSON or EXPLAIN ANALYZE on the slow query and interpret the output. However, acting on findings (adding indexes, rewriting queries) may touch multiple queries across a component, pushing slightly beyond e1.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). EXPLAIN ANALYZE is a diagnostic technique, not a load-bearing architectural choice. It applies to database debugging sessions rather than imposing ongoing structural weight. The applies_to scope (web, cli) is broad, but the concept itself doesn't shape the codebase — it's a point-in-time tool.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly states: 'EXPLAIN without ANALYZE shows how a query runs — it shows what the planner *thinks* will happen based on statistics; EXPLAIN ANALYZE shows what actually happens.' This is a documented gotcha that most developers eventually learn, but using EXPLAIN alone and trusting estimated rows is a common mistake that leads to misdiagnosis.

About DEBT scoring →

Also Known As

EXPLAIN query plan execution plan EXPLAIN ANALYZE

TL;DR

The database command that shows the actual execution plan of a query — revealing sequential scans, missing indexes, and row estimate errors that cause slow performance.

Explanation

EXPLAIN shows the planner's estimated plan. EXPLAIN ANALYZE actually executes the query and shows real row counts, actual time, and buffer usage. Key things to look for: Seq Scan on large tables (needs an index), Nested Loop with high row estimates (join order problem), estimated vs actual rows diverging significantly (stale statistics), and Sort operations that could be eliminated with an index. PostgreSQL's EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) gives the most detail.

Diagram

flowchart TD
    QUERY[Slow SQL query] --> EXPLAIN[EXPLAIN ANALYZE]
    EXPLAIN --> PLAN[Query Plan]
    PLAN --> CHECK{Scan type?}
    CHECK -->|Seq Scan - full table| BAD[Missing index<br/>add index on filter column]
    CHECK -->|Index Scan - fast| GOOD[Index used correctly]
    CHECK -->|Nested Loop huge rows| STAT[Stale statistics<br/>run ANALYZE]
    subgraph Key Metrics
        ROWS[rows estimate vs actual<br/>big diff means stale stats]
        COST[cost= startup..total<br/>higher = slower]
        LOOPS[loops=N means<br/>executed N times]
    end
    style BAD fill:#f85149,color:#fff
    style GOOD fill:#238636,color:#fff

Common Misconception

✗ EXPLAIN without ANALYZE shows how a query runs — it shows what the planner *thinks* will happen based on statistics; EXPLAIN ANALYZE shows what actually happens.

Why It Matters

Every slow query investigation starts with EXPLAIN ANALYZE — without it you are guessing; with it the bottleneck is usually obvious within seconds.

Common Mistakes

  • Using EXPLAIN without ANALYZE — estimated rows can be wildly wrong; always use ANALYZE for diagnosis.
  • Not running ANALYZE on tables after bulk inserts — stale statistics cause the planner to choose wrong indexes.
  • Optimising based on a small dev dataset — plans change dramatically with production row counts.
  • Not using EXPLAIN (BUFFERS) in PostgreSQL — buffer hits vs disk reads reveals I/O bottlenecks.

Code Examples

✗ Vulnerable
-- Investigating slow query without EXPLAIN:
SELECT * FROM orders WHERE user_id = 42 AND status = 'pending';
-- 'It's slow' — no idea why
-- Adding random indexes hoping one helps
✓ Fixed
-- PostgreSQL — full detail:
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT * FROM orders WHERE user_id = 42 AND status = 'pending';

-- Red flags to look for:
-- Seq Scan on orders (rows=1000000) → needs index
-- actual rows=1 vs estimated rows=50000 → stale stats, run ANALYZE
-- Buffers: read=8420 → disk I/O, consider covering index
-- Sort (cost=...) → add index with ORDER BY column

Added 15 Mar 2026
Edited 22 Mar 2026
Views 202
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 1 ping M 2 pings T 0 pings W 0 pings T 0 pings F 0 pings S
No pings yet today
No pings yesterday
Amazonbot 20 Perplexity 11 Ahrefs 11 PetalBot 11 Scrapy 10 Google 9 SEMrush 9 Bing 9 ChatGPT 6 Unknown AI 5 Sogou 4 Applebot 2 Brave Search 2 Meta AI 1 Qwen 1 Twitter/X 1 Baidu 1
crawler 107 crawler_json 5 pre-tracking 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Database database A database is an organized collection of data stored electronically, designed so programs can efficiently retrieve, add, update, and delete information.

Nearly every application needs to remember information between sessions. Databases provide the reliable, fast, and organized storage that makes persistent data possible at any scale.

💡 Always use prepared statements with placeholders—never concatenate user input directly into database queries.

Ask Codex about Database →
⚡ DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
Run EXPLAIN FORMAT=JSON or EXPLAIN ANALYZE on every slow query — look for type:ALL (full scan), rows>10000, and Extra:Using filesort as the three most expensive signals
📦 Applies To
PHP 5.0+ web cli
🔗 Prerequisites
🔍 Detection Hints
No EXPLAIN analysis on queries over 100ms; queries with type:ALL in EXPLAIN; missing index on high-cardinality WHERE column
Auto-detectable: ✓ Yes mysql-slow-query-log percona-toolkit laravel-debugbar
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: Function


✓ schema.org compliant