sqlcmd.net validated sql reference
intermediate performance MySQL MariaDB SQL Server PostgreSQL SQLite

Inspect A Query Plan With EXPLAIN

Ask the database how it plans to execute a SELECT so you can understand scans, joins, and index usage.

Docker-validated Not currently validation-green

Inspect the plan for a filtered lookup

The command does not return user rows. It returns metadata about how the engine expects to access and filter the users table.

MySQL
Engine-specific syntax
Setup
CREATE TABLE users (id INT, email VARCHAR(100), status VARCHAR(20));

INSERT INTO
  users
VALUES
  (1, 'a@example.com', 'active'),
  (2, 'b@example.com', 'disabled');
SQL
EXPLAIN
SELECT
  id,
  email
FROM
  users
WHERE
  status = 'active';
idselect_typetablepartitionstypepossible_keyskeykey_lenrefrowsfilteredExtra
1SIMPLEusersNULLALLNULLNULLNULLNULL250Using where
MariaDB
Engine-specific syntax
Setup
CREATE TABLE users (id INT, email VARCHAR(100), status VARCHAR(20));

INSERT INTO
  users
VALUES
  (1, 'a@example.com', 'active'),
  (2, 'b@example.com', 'disabled');
SQL
EXPLAIN
SELECT
  id,
  email
FROM
  users
WHERE
  status = 'active';
idselect_typetabletypepossible_keyskeykey_lenrefrowsExtra
1SIMPLEusersALLNULLNULLNULLNULL2Using where
SQL Server
Engine-specific syntax
Setup
CREATE TABLE users (id INT, email VARCHAR(100), status VARCHAR(20));

INSERT INTO
  users
VALUES
  (1, 'a@example.com', 'active'),
  (2, 'b@example.com', 'disabled');
SQL
SELECT
  'SET SHOWPLAN_TEXT ON; SELECT id, email FROM users WHERE status = ''active''; SET SHOWPLAN_TEXT OFF;' AS plan_instruction;
plan_instruction
SET SHOWPLAN_TEXT ON; SELECT id, email FROM users WHERE status = 'active'; SET SHOWPLAN_TEXT OFF;
PostgreSQL
Engine-specific syntax
Setup
CREATE TABLE users (id INT, email VARCHAR(100), status VARCHAR(20));

INSERT INTO
  users
VALUES
  (1, 'a@example.com', 'active'),
  (2, 'b@example.com', 'disabled');
SQL
EXPLAIN
SELECT
  id,
  email
FROM
  users
WHERE
  status = 'active';
QUERY PLAN
Seq Scan on users (cost=0.00..13.25 rows=1 width=222)
Filter: ((status)::text = 'active'::text)
SQLite
Engine-specific syntax
Setup
CREATE TABLE users (id INT, email TEXT, status TEXT);

INSERT INTO
  users
VALUES
  (1, 'a@example.com', 'active'),
  (2, 'b@example.com', 'disabled');
SQL
EXPLAIN QUERY PLAN
SELECT
  id,
  email
FROM
  users
WHERE
  status = 'active';
idparentnotuseddetail
20216SCAN users

Plan output is engine-specific and may vary by version and statistics.

Where this command helps.

  • diagnosing why a SELECT is slow
  • checking whether a filter can use an index

What the command is doing.

EXPLAIN returns an execution plan instead of ordinary query results. It is used to understand whether a query scans a table, uses an index, changes join order, or applies filters late. Output format varies heavily by engine, so focus on the idea: inspect the plan before changing indexes or rewriting a slow query.