# Query Plan

> The steps a database picks to answer a query. EXPLAIN shows them.

**Field:** Software Development  
**Category:** Databases  
**Also known as:** Execution Plan, EXPLAIN, Query Execution Plan

## Think of it like

Think of it like the route a sat nav picks before you drive. You can look at it and see if it is a good one.

## Definition

A query plan is the set of steps a database picks to answer a query. It says which tables it reads first, whether it uses an index and how it joins them. You see it by putting EXPLAIN in front of the query. A plan that scans a whole big table is often the cause of a slow page. Reading plans is the first step in making a slow query fast.

## Example

Jack's search takes 3 seconds. EXPLAIN shows a scan of all 2 million rows, so he adds an index and the plan switches to a search.

## Example code

```sql
EXPLAIN QUERY PLAN SELECT * FROM customers WHERE city = 'London';
-- SCAN customers
```

In SQLite, SCAN means it reads every row to find the matches.

## Why it matters

You cannot fix a slow query by guessing. The plan shows where the time goes.

## Common mistake

Testing the plan on a tiny copy of the data. With 50 rows a scan is fine; with 5 million it is not.

## Three principles

- **The chosen steps.** How the database will answer.
- **EXPLAIN shows it.** Put it before the query.
- **Look for scans.** Full scans of big tables are slow.

## Related terms

- [Database Index](https://learn.benibix.com/term/development/database-index)
- [Database Query](https://learn.benibix.com/term/development/query)
- [SQL Join](https://learn.benibix.com/term/development/join)
- [Structured Query Language (SQL)](https://learn.benibix.com/term/development/sql)

---

Source: https://learn.benibix.com/term/development/query-plan
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
