DELAPARRA
Index
Color
NL
Category: SQL

EXPLAIN / EXPLAIN ANALYZE

Explained by Updated

What is EXPLAIN / EXPLAIN ANALYZE?

EXPLAIN / EXPLAIN ANALYZE: Shows the query plan (estimated). EXPLAIN ANALYZE actually runs the query and reports real timing and row counts. EXPLAIN shows how the database plans to run a query: which indexes it uses, how it joins tables and how many rows it expects to read. EXPLAIN ANALYZE actually runs the query and reports real times and row counts.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about EXPLAIN / EXPLAIN ANALYZE

How is EXPLAIN / EXPLAIN ANALYZE used in practice?

It is the first tool to reach for when a query is slow. The plan usually shows the cause straight away, such as a full table scan where you expected an index, or a join reading millions of rows.

What should you keep in mind with EXPLAIN / EXPLAIN ANALYZE?

Look for big gaps between estimated and actual row counts, scans on large tables, and filesorts on big result sets. Be careful with EXPLAIN ANALYZE on statements that change data, because it really executes them. Wrap those in a transaction you roll back. The plan for production data can differ from your laptop's, so test with realistic volumes.

What does an example of EXPLAIN / EXPLAIN ANALYZE look like?

EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 42;

At a glance

CategorySQL
Explained by
Updated

More SQL terms

All terms starting with E

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.