Skip to Content
dbmcp

explain

Show the execution plan of a SQL query, with optional EXPLAIN ANALYZE on PostgreSQL and MySQL, or ANALYZE on MariaDB

Return the execution plan for a SQL query. Supports an optional analyze parameter for actual execution statistics on PostgreSQL and MySQL/MariaDB; MariaDB runs it as ANALYZE FORMAT=JSON, its replacement for EXPLAIN ANALYZE. EXPLAIN ANALYZE is only allowed for SELECT statements since it actually executes the query, even when read-only mode is disabled. The MySQL or MariaDB form follows database.backend, so set it to match the server. Every EXPLAIN runs read-only (see Read-Only Transactions), so on MySQL/MariaDB plain EXPLAIN of write statements is rejected; PostgreSQL still plans them. SQLite always uses EXPLAIN QUERY PLAN and does not support ANALYZE. Always available regardless of read-only mode.

On PostgreSQL and MySQL/MariaDB, an optional timeout argument (seconds) gives a known-slow analyze more time, up to the operator's cap; see Per-Call Timeout.

Plan row keys follow the column order, as in read.

With column rules, the plan of a statement that touches a ruled table is pruned to value-free keys (plan structure, table and index names, access types, estimates), and analyze on such a statement is refused. On MariaDB, analyze is refused on every statement while rules exist.