Read a query plan#

Ask the database how it intends to run a statement, then measure the real cost where the engine allows it.

A query plan shows how the database intends to run a statement: which tables it reads, in what order, and which indexes it uses. It is how you work out why a query is slow, and whether an index does its job.

Select Explain, or press Cmd+Shift+E, to see the plan for the statement in the editor. Explain does not run the query. It only asks the database how it would run it. The plan opens as a tree below the results, which you can resize or close.

Measure a query as it runs#

Some engines can go further and measure a query as it runs. Where the engine supports it (PostgreSQL and SQL Server), an Explain analyze button sits next to Explain.

Explain analyze does run the statement, so its numbers are real rather than estimated. That also means a statement that changes data changes the data when you analyse it. The button therefore asks you to confirm before it runs, with Run and measure. Use it on read-only queries, or on a database where the change is safe.