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 MariaDB PostgreSQL
Engine-specific syntax
Setup
CREATE TABLE users (id INT, email VARCHAR(100), status VARCHAR(20));

INSERT INTO
  users
VALUES
  (1, '[email protected]', 'active'),
  (2, '[email protected]', 'disabled');
SQL
EXPLAIN
SELECT
  id,
  email
FROM
  users
WHERE
  status = 'active';
SQL Server
Engine-specific syntax
Setup
CREATE TABLE users (id INT, email VARCHAR(100), status VARCHAR(20));

INSERT INTO
  users
VALUES
  (1, '[email protected]', 'active'),
  (2, '[email protected]', 'disabled');
SQL
SET
  SHOWPLAN_TEXT ON;

SELECT
  id,
  email
FROM
  users
WHERE
  status = 'active';

SET
  SHOWPLAN_TEXT OFF;
SQLite
Engine-specific syntax
Setup
CREATE TABLE users (id INT, email TEXT, status TEXT);

INSERT INTO
  users
VALUES
  (1, '[email protected]', 'active'),
  (2, '[email protected]', 'disabled');
SQL
EXPLAIN QUERY PLAN
SELECT
  id,
  email
FROM
  users
WHERE
  status = 'active';

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.