Ad space (banner)
🗄️SQL Lessons
Lesson 38 / 50

Inspecting Query Plans with EXPLAIN QUERY PLAN

This lesson covers inspecting a query's execution plan with EXPLAIN QUERY PLAN, so you can investigate why a query is slow. It's for anyone searching "SQL EXPLAIN QUERY PLAN tutorial."

Prefixing a query with EXPLAIN QUERY PLAN shows how the database intends to execute it — whether it scans the whole table or uses an index — the natural first step when investigating a slow query.

The example runs EXPLAIN QUERY PLAN SELECT * FROM students WHERE score >= 80; to see the execution plan for that query. Look for whether the plan mentions using an index versus scanning the entire table.

A common early mistake is being intimidated by the jargon in the output — it looks dense at first, but even just distinguishing "SCAN" (full table scan) from "SEARCH" (index-assisted lookup) gives you a solid clue about performance. Guessing why a query is slow is unreliable, but the execution plan gives you actual evidence to work from — an essential investigative tool whenever you're asked to improve performance in a real project.

SQL
OUTPUT

💡 The SQL engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)