DBAtlas · Database operations atlas

Get a query's execution plan (EXPLAIN)

Oracle

EXPLAIN PLAN FOR
SELECT * FROM customer WHERE city = 'Ankara';
SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);
-- For the actual executed plan:
-- SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('&sql_id', NULL, 'ALLSTATS LAST'));

EXPLAIN PLAN gives the estimated plan; for actual row counts use DISPLAY_CURSOR + STATISTICS_LEVEL=ALL.

PostgreSQL

EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT * FROM customer WHERE city = 'Ankara';

ANALYZE ACTUALLY executes the query (be careful with INSERT/UPDATE/DELETE; try it inside a transaction and ROLLBACK).

MySQL

EXPLAIN ANALYZE
SELECT * FROM customer WHERE city = 'Ankara';
-- Estimate only (does not execute): EXPLAIN FORMAT=JSON SELECT ...;

EXPLAIN ANALYZE (MySQL 8.0.18+) executes the query; FORMAT=JSON gives details without executing it.

SQL Server

SET STATISTICS PROFILE ON;
SELECT * FROM dbo.customer WHERE city = 'Ankara';
SET STATISTICS PROFILE OFF;
-- Estimated plan only (does not execute):
-- SET SHOWPLAN_XML ON;

In SSMS, 'Include Actual Execution Plan' (Ctrl+M) shows the graphical plan.

MongoDB

db.customer.find({ city: "Ankara" }).explain("executionStats")

executionStats shows the actual number of documents returned and index usage (IXSCAN vs COLLSCAN).

Redis

# Not applicable: Redis has no query planner.
# The complexity of each command is documented (e.g. GET O(1), SORT O(N+M*log(M))).

Performance comes from command complexity and key/data structure size; measure it with SLOWLOG.

Open in DBAtlas →