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

MySQL EXPLAIN

Database Intermediate
debt(d9/e3/b3/t7)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). The detection_hints state automated: no, and the code_pattern relies on slow query log entries — meaning missing EXPLAIN usage (or misreading its output) produces no warnings, no linter signals, and no tooling alerts. Performance degradation from unanalyzed queries is only noticed when users experience slowness in production.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is a single EXPLAIN SELECT invocation, but acting on the results (adding an index or rewriting a query) typically involves a small, localized change — one or a few files/migrations. It rarely requires cross-cutting refactors, so e3 is appropriate.

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

Closest to 'localised tax' (b3). EXPLAIN is a diagnostic tool rather than a structural choice baked into the codebase. Its burden is localized: the developer must remember to run it and interpret it for slow queries, but it doesn't impose a persistent tax on every future maintainer or every code change.

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

Closest to 'serious trap' (t7). The misconception field is explicit: developers assume EXPLAIN shows actual execution, but standard EXPLAIN only shows estimated plans. This directly contradicts how EXPLAIN ANALYZE (PostgreSQL) works by default, and many developers coming from other databases or newer MySQL versions are misled into trusting row estimates as actuals — a serious behavioral contradiction.

About DEBT scoring →

Also Known As

MySQL EXPLAIN query query execution plan MySQL EXPLAIN ANALYZE

TL;DR

A MySQL query analysis command showing the execution plan — which indexes are used, how many rows are scanned, and where bottlenecks are.

Explanation

EXPLAIN prefixed to a SELECT/UPDATE/DELETE shows the query execution plan. Key columns: 'type' (ALL = full scan, ref = index lookup, eq_ref = unique index — lower is better), 'key' (which index was chosen), 'rows' (estimated rows examined), 'Extra' (Using filesort, Using temporary — both indicate optimisation opportunities). EXPLAIN ANALYZE (MySQL 8+) executes the query and shows actual vs estimated row counts.

Common Misconception

EXPLAIN shows the actual query execution. Standard EXPLAIN shows the estimated plan only — use EXPLAIN ANALYZE (MySQL 8+) or EXPLAIN FORMAT=JSON for actual execution data.

Why It Matters

EXPLAIN is the primary tool for diagnosing slow queries. A single EXPLAIN output immediately reveals whether a query is doing a full table scan, which index it uses, and whether a sort operation is hitting disk.

Common Mistakes

  • Not running EXPLAIN before adding an index — the index may already exist or may not be used.
  • Ignoring the 'Extra' column — 'Using filesort' and 'Using temporary' are expensive operations.
  • Running EXPLAIN ANALYZE on a slow write query in production — it executes the query, causing the write.

Avoid When

  • Do not run EXPLAIN ANALYZE on write queries (INSERT/UPDATE/DELETE) in production — it actually executes them.

When To Use

  • Run EXPLAIN on any query that feels slow or affects many rows.
  • Run EXPLAIN before and after adding an index to verify it is actually used.

Code Examples

✗ Vulnerable
-- Debugging slow query by guessing
-- Adding indexes blindly without checking EXPLAIN first
✓ Fixed
-- Check execution plan
EXPLAIN SELECT * FROM orders WHERE user_id = 42 AND status = 'pending';
-- Look for: type=ref or better, key=idx_user_status, rows=small number

-- MySQL 8+: actual execution stats
EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 42;

Added 31 Mar 2026
Views 49
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 2 pings S 2 pings S 1 ping M 0 pings T 0 pings W 1 ping T 0 pings F 3 pings S 0 pings S 0 pings M 0 pings T 0 pings W 2 pings T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Perplexity 6 Google 5 Scrapy 5 Unknown AI 3 Ahrefs 3 SEMrush 3 Meta AI 2 Claude 2 PetalBot 2 Sogou 1 Majestic 1
crawler 30 crawler_json 2 pre-tracking 1
DEV INTEL Tools & Severity
⚙ Fix effort: Low
⚡ Quick Fix
Run EXPLAIN SELECT ... on any slow query — if type=ALL and rows is large, add an index on the WHERE/JOIN column
📦 Applies To
web cli
🔗 Prerequisites
🔍 Detection Hints
Slow query log entries or queries without index visible in EXPLAIN
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Low ✗ Manual fix Fix: Medium Context: File


✓ schema.org compliant