---
title: "Read the query plan · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/queries-and-indexes/query-plans
updated: 2026-10-20
licence: "All rights reserved"
---

# Read the query plan

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [Queries and indexes](https://agentwranglers.se/playbook/data/queries-and-indexes)
- Rule: Before you change a slow query or add an index, read its plan. Check again after the change.
- How: Run `EXPLAIN ANALYZE` in PostgreSQL, `EXPLAIN ANALYZE` in MySQL 8.0.18 or later, or `EXPLAIN QUERY PLAN` in SQLite on a copy with realistic data. Small test tables hide the problems, because a scan of 10 rows is always fast. `EXPLAIN ANALYZE` executes the statement, so wrap an `UPDATE` or `DELETE` in a transaction and roll it back.
- Check: The change notes for each performance fix show the plan and the time before and after, such as "from 840 ms to 3 ms".

Example:

```sql
BEGIN;
EXPLAIN ANALYZE DELETE FROM sessions WHERE expires_at < now();
ROLLBACK;
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/queries-and-indexes/query-plans`.

- Previous: [Index the queries you run](https://agentwranglers.se/playbook/data/queries-and-indexes/index-the-queries-you-run)
- Next: [Load related rows in one query](https://agentwranglers.se/playbook/data/queries-and-indexes/no-n-plus-one)
- [Queries and indexes](https://agentwranglers.se/playbook/data/queries-and-indexes)
