MySQL EXPLAIN Operations


MySQL reference: http://dev.mysql.com/doc/refman/5.6/en/explain-output.html

Index and Table Access

MySQL’s explain plan tends to give a false sense of safety because it says so much about indexes being used. Although technically correct, it does not mean that it is using the index efficiently. The most important information is in the TYPE column of the MySQL’s explain output—but even there, the keyword INDEX doesn’t indicate proper indexing.

eq_ref

Performs a B-tree traversal only. The database uses this operation if a primary key or unique constraint ensures that the search criteria will match no more than one entry. See also Anatomy of an SQL Index.

ref, range

Performs a B-tree traversal and walks through the leaf nodes to find all matching entries (similar to INDEX RANGE SCAN). See also Anatomy of an SQL Index.

index

Reads the entire index—all rows—in the index order (similar to INDEX FULL SCAN).

ALL

Reads the entire table—all rows and columns—as stored on the disk. Besides high IO rates, a table scan must also inspect all rows from the table so that it can also put a considerable load on the CPU. See also “Full Table Scan”.

Using Index (in the “Extra” column)

When the “Extra” column shows “Using Index”, it means that the table is not accessed because the index has all the required data. Think of “using index ONLY”. See also Clustering Data: The Second Power of Indexing.

PRIMARY (in the “key” or “possible_keys” column)

PRIMARY is the name of the automatically created index for the primary key.

About our book “SQL Performance Explained”
Probably the best book on SQL performance I've read
Guillaume Lelarge on Amazon.co.uk (5 stars)

Sorting and Grouping

using filesort (in the “Extra” column)

“using filesort” in the Extra column indicates an explicit sort operation—no matter where the sort takes place (main memory or on disk). “Using filesort” needs large amounts of memory to materialize the intermediate result (not pipelined). See also “Indexing Order By”.

Top-N Queries

implicit: no “using filesort” in the “Extra” column

A MySQL execution plan does not show a top-N query explicitly. If you are using the limit syntax and don’t see “using filesort” in the extra column, it is executed in a pipelined manner. See also “Querying Top-N Rows”.

About the Author

As an author, trainer, and coach Markus Winand specializes in helping developers cope with SQL performance issues. He also published the book SQL Performance Explained and tweets his best performance tips via @SQLPerfTips.http://winand.at/

Recent Questions at Ask.Use-The-Index-Luke.com

0
votes
1
answer
99
views

We want to buy the book but I can't

Jul 18 at 21:36 Markus Winand ♦♦ 541
book
0
votes
2
answers
155
views
0
votes
0
answers
809
views

Performance very bad in Postgresql 9.3

Jul 08 at 11:54 Markus Winand ♦♦ 541
performance issue