What is EXPLAIN ANALYZE?
EXPLAIN ANALYZE executes a statement and reports measurements from that execution alongside its plan.
Plain EXPLAIN describes the planned work without executing the statement to collect those measurements.
When to use EXPLAIN ANALYZE
Section titled “When to use EXPLAIN ANALYZE”Use an actual plan to compare the database’s estimates with the work a query performs. This can help investigate a slow query after you inspect its estimated plan.
Review the statement and active connection before collecting an actual plan. The statement runs and can change data or consume substantial server resources.
Explain with AI starts with plain EXPLAIN.
TableAI asks for confirmation before running EXPLAIN ANALYZE.
See explain a query plan with AI for that workflow.
Database syntax
Section titled “Database syntax”These are the actual-plan forms TableAI uses for PostgreSQL, MySQL, and MariaDB.
Each example reads up to ten rows from the Bookstore demo’s books table.
PostgreSQL
Section titled “PostgreSQL”EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)SELECT * FROM books LIMIT 10;BUFFERS adds buffer access information to the PostgreSQL plan.
For MySQL:
EXPLAIN ANALYZE SELECT * FROM books LIMIT 10;MariaDB
Section titled “MariaDB”ANALYZE FORMAT=JSON SELECT * FROM books LIMIT 10;MariaDB uses ANALYZE FORMAT=JSON for this purpose.
Its actual-plan syntax differs from MySQL’s.
Queries with parameters
Section titled “Queries with parameters”An actual execution needs values for parameters such as $1 or ?.
For a recorded PostgreSQL, MySQL, or MariaDB query without those values, TableAI asks you to supply them first.
Review the completed statement in the SQL editor before execution.
Continue with diagnose database performance to inspect the surrounding workload, or slow query troubleshooting for a timeout.