Working with the EXPLAIN statement

The EXPLAIN statement is the main tool to understand how a statement is executed within a server. In MariaDB 10, this works not only with the SELECT statements, but also with the UPDATE and DELETE statements. The syntax of the EXPLAIN statement is:

EXPLAIN [EXTENDED] <statement>;

The EXTENDED clause adds a column to the output and generates a note (which can be seen with the SHOW WARNINGS command) containing statement as it has been internally rewritten by the optimizer.

After MariaDB 10, another property of this command was added, shown as follows:

SHOW EXPLAIN FOR <thread_id>;

This command allows us to obtain the execution plan from a running statement. This is useful when a statement is taking a lot of time and ...

Get Mastering MariaDB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.