Help › Run queries

See a query's execution plan

Show a statement's execution plan as a tree, measure it with Explain Analyze without keeping its changes, and read the heaviest steps.

Querlyn 0.1.0 is not released yet. This help describes it ahead of release.

When a query is slow, the database's plan says why: which tables it reads, in what order, with which indexes. Querlyn shows the plan as a tree you can read, with the expensive steps marked.

Explain and Explain Analyze

ExplainExplain Analyze
What you getThe plan the database would use, with its estimatesThe plan it did use, with real row counts and times
Does the statement run?NoYes, inside a transaction that Querlyn always rolls back (on MongoDB, a write is evaluated and not applied)
How to start itExplain in the bar above the editor, ⌘E on macOS or Ctrl+E on Windows and Linux, or Query › ExplainAnalyze in the bar, or Query › Explain Analyze
Where it worksEvery database except SingleStorePostgreSQL (and CockroachDB and YugabyteDB), MySQL 8.3 and later, TiDB, MariaDB, SQL Server, DuckDB, Oracle Database, MongoDB

Both work on one statement: the one the cursor is in, or the selection when it holds exactly one statement. Write the statement itself, without EXPLAIN in front. A statement with parameters asks for their values first.

When Analyze is not available, the button is disabled and its tooltip says why: the database has no measured plans, or this kind of statement cannot be measured there.

Explain Analyze never keeps changes

Explain Analyze really runs the statement, so that it can measure it. To make that safe, Querlyn runs it inside a transaction and always rolls that transaction back, also when the statement fails or you cancel. An UPDATE you analyze changes nothing.

  • If your tab already has a transaction open, your earlier changes in it are kept and the transaction stays open; only the analyzed statement is undone.
  • A plain SELECT is rolled back too, because a query can call a function that writes.

Warning: A rollback cannot undo everything. Sequences that the statement advanced stay advanced, and anything a trigger or function did outside the database, such as calling another system, is not undone.

On a Production connection, Querlyn asks before analyzing a statement that may change data. The question is titled Explain Analyze on Production? and its button reads Run and Roll Back. On a read-only connection, analyzing such a statement is refused; Explain is always allowed.

On MongoDB there is no transaction to roll back: the server measures a write without applying it (executionStats), so no document changes, but the documents it reads still take time and load on the server. Production asks before analyzing a write, as above.

Where a rollback could not be trusted, only Explain is offered. That is the case for a write to a MySQL or MariaDB table that is not on a transactional storage engine, for EXEC on SQL Server (a procedure can commit), and for statements that change the structure on MySQL and Oracle.

Read the plan

The plan appears on the Plan tab of the results pane. Each row is one step; steps that feed another step are indented under it.

ColumnMeaning
OperationWhat the step does, such as a scan, a join or a sort.
ObjectThe table or index it works on.
Est. rowsHow many rows the database expected.
Actual rows, LoopsAfter Explain Analyze: how many rows really came out, and how often the step ran.
Own time or Own costThe step's own time (analyzed) or estimated cost, without the steps under it.
ShareA bar: this step's part of the whole.

What to look for:

  • The heaviest steps are red: the three largest shares, when they are at least 10 % each. Start there.
  • ▲ and ▼ mark estimates that were off by ten times or more. ▲ means the database expected far fewer rows than it got, ▼ far more.
  • A step that never ran says so.

The line above the tree sums the plan up: estimated or analyzed, how many steps, the total, how many estimates were off, and any warnings from the database.

ToDo this
Move through the steps↑ on macOS or Up on Windows and Linux, ↓ on macOS or Down on Windows and Linux, ↖ on macOS or Home on Windows and Linux, ↘ on macOS or End on Windows and Linux
Close or open a step's children← on macOS or Left on Windows and Linux, → on macOS or Right on Windows and Linux
See everything about a stepSelect it and press ↩ on macOS or Enter on Windows and Linux, or choose Details (Query › Toggle Plan Details). The chevron on the details' edge hides them, the strip on the right shows them again, and their edge drags to make them wider.
Copy the plan as the database returned itCopy Plan (Query › Copy Plan)

The Raw tab shows the database's own output, unchanged, with a Copy button. Where masked columns are masked and the plan quotes one's value, the plan shows the placeholder instead, and the Raw output and Copy Plan are not available.

Compare plans

Every plan is kept in its tab, so you can put two side by side: before and after an index, or the same statement on another connection. Compare and On Another Connection in the bar above the plan (Query › Compare Plans…, Query › Explain on Another Connection…) open the comparison. See Compare two query plans.

What differs by database

DatabaseNotes
PostgreSQLExplains queries, INSERT, UPDATE, DELETE, MERGE and CREATE TABLE … AS.
MySQLExplain Analyze needs 8.3 or later, and measures queries, multi-table UPDATE and DELETE, and INSERT … SELECT; other writes get the estimated plan only.
MariaDBExplain Analyze also measures single-table UPDATE and DELETE.
SQL ServerThe estimated plan is compiled without running.
SQLiteThe plan's structure only: no rows, costs or times.
DuckDBEstimated plans have row estimates but no costs, so no step is marked heaviest until you analyze.
Amazon RedshiftRedshift's text plan, with where each step runs.
CockroachDBCockroachDB's own plan, with the table and index each step reads, a warning on a full scan, and its index recommendations.
TiDBTiDB's own plan (6.5 and later), with where each operator runs; a table without statistics is pointed out.
SingleStoreNot offered.
ClickHouseSELECT statements only.
Oracle DatabaseExplain Analyze needs a user that may read the performance views (SELECT_CATALOG_ROLE).
SnowflakeThe plan shows partitions and bytes scanned, not row estimates.
BigQueryA dry run: the bytes the statement will read, without running it. Once the statement has run in the tab, also the stages of that run, with the rows each read and wrote. No Explain Analyze.
MongoDBThe query planner's winning plan for a find, an aggregate, a count, distinct or a write, with the index each step uses; a collection scan is pointed out. Explain Analyze measures each stage: documents returned, documents and index keys examined (the Examined column), and its own time; where no stage took measurable time, the share is of what was examined.
CassandraCassandra has no plans to estimate: Explain runs a SELECT with tracing and shows its trace, each node with its steps and their times, tombstones pointed out. The read happens (its first page of rows), so a Production connection asks first. Writes are traced with TRACING ON in the editor instead.

An explain is not recorded in the query history.

Help for Querlyn 0.1.0. All help topics