
Source: Understanding SQL Queries Using the EXPLAIN Command
1. What is the EXPLAIN Command?
The EXPLAIN command is a powerful SQL feature that allows you to view the query execution plan. The execution plan is a breakdown of how the SQL engine will process your query, from selecting the best indexes to applying joins, filtering, and sorting. With this tool, you can spot potential bottlenecks and inefficiencies in your query.

1.1 Understanding the Basics of EXPLAIN
The simplest way to use EXPLAIN is to prefix your SQL query with the EXPLAIN keyword. For example:
EXPLAIN SELECT * FROM employees WHERE department = 'HR';
Running this query doesn’t return the actual data; instead, it provides a detailed breakdown of how the SQL engine plans to execute this query.
1.2 The Output of EXPLAIN
The output of EXPLAIN generally consists of several columns, including but not limited to:
- id: Identifies the order of execution.