table
Table access is via an access_type which describes how the table is accessed or joined to other tables in the query.
Detailed Descriptionβ
Table access is via an access_type
which describes how the table is accessed or joined to other tables in the query.
There are other properties such as the table_name
, query_cost
, rows_examined_per_scan
and several others depending on the access_type
which then give further details about the efficiency of the access type.
Table access types (access_type
)β
The following list describes the access types, ordered from the best type to the worst:
systemβ
The system
access type is a special type of const
join type on a system table with only one row. This is a very fast access.
MySQL Documentation - access type system
constβ
The const
access type is accessing a table with at most one row in. This table is ready at the start of the query and is very fast due to only being read once. const
accesses can be seen reading a single value from a primary key or a unique index.
MySQL Documentation - access type const
eq_refβ
The eq_ref
access method joins a single row in the first data source with a single row in the second data source. This is a very fast access method as it requires primary keys or unique not null indexes as sources of data.
MySQL Documentation - access type eq_ref
refβ
The ref
access method is used to join data sources where uniqueness cannot be guaranteed. Where the access key returns a low number of records, this access method performs well.
MySQL Documentation - access type ref
fulltextβ
The fulltext
join type uses a FULLTEXT index to join.
MySQL Documentation - access type fulltext
ref_or_nullβ
Similar to ref
join access, but the ref_or_null
has the ability to do an extra search for NULL
values. This join method is often used with subqueries and to search for NULL
values.
MySQL Documentation - access type ref_or_null
index_mergeβ
An index_merge
join method is in use. The returned key
column contains a list of indexes to be used.
MySQL Documentation - access type index_merge
unique_subqueryβ
The unique_subquery
join type is an index lookup and replaces the eq_ref
method for some IN
subqueries. Like eq_ref
, unique_subquery
requires primary keys or unique not null indexes.
MySQL Documentation - access type unique_subquery
index_subqueryβ
Similar to unique_subquery
, index_subquery
replaces certain IN subqueries, but it can be used for non-unique indexes.
MySQL Documentation - access type index_subquery
rangeβ
The range
join type retrieves a given range of rows using an index to select the rows. range
can be used where the key column is compared to a constant.
MySQL Documentation - access type range
indexβ
The index
join type can be used if all the required columns are covered by indexes. index
can be used where all the queried columns are in a single index.
MySQL Documentation - access type index
ALLβ
The ALL
join type carries out a full table scan for each combination of rows from the previous table. Performance of ALL
queries can be very bad and are best avoided. This can be done by adding indexes that support the query.
MySQL Documentation - access type ALL
Other useful propertiesβ
table_nameβ
The table_name
is the row source for the query block. It can be:
- an actual table name
- a union shown as
<union*M, N*>
- a derived row source shown as
<derived*N*>
- a subquery shown as
<subquery*N*>
partitionsβ
Shows the partitions
from which rows match the query. For non-partitioned tables, the value is NULL.
MySQL Documentation - Explain partitions
keyβ
The key
column shows the actual index selected by the planner to satisfy this part of the query. This is usually from the values show in the possible_keys
column but it is possible that a scan of an index covering all required columns that is not in the possible list will be used.
You can use FORCE INDEX
, USE INDEX
or IGNORE INDEX
query hints to use or ignore specific indexes.
If key
is NULL then no suitable index was found.
MySQL Documentation - Explain key
rows_examined_per_scanβ
The rows_examined_per_scan
column indicates the number rows scanned in this section of the query. When used with the filtered
column and the rows_prodcued_per_join
column, you can get an understanding of how much data your query will read and how selective your query is.
If filtered
is a low percentage and rows_examined_per_scan
is much higher than rows_produced_per_join
then it is possible your query efficiency could be improved by indexing.
rows_produced_per_joinβ
The rows_prodcued_per_join
column indicates the number rows returned in this section of the query. When used with the filtered
column and the rows_examined_per_scan
column, you can get an understanding of how much data your query will read and how selective your query is.
If filtered
is a low percentage and rows_examined_per_scan
is much higher than rows_produced_per_join
then it is possible your query efficiency could be improved by indexing.
rowsβ
The rows
column indicates the estimated number of the the planner believes will be returned by the query block. With InnoDB
tables this is an estimate only.
filteredβ
TheΒ filtered
column indicates an estimated percentage of table rows that are filtered by the table condition. The maximum value is 100, which means no filtering of rows occurred.
MySQL Documentation - Explain filtered
read_costβ
Cost of reading for each table used in the query block.
eval_costβ
Cost of condition evaluation for each table in the query block.
prefix_costβ
Cost of executing prefix join in the query block.
query_costβ
TODO
data_read_per_joinβ
Estimated amount of data from the table processed during single query block execution.
using_indexβ
This will be true or false to indicate whether an index is being used.
possible_keysβ
The possible_keys
column shows the indexes which may be used to satisfy the query. If this column is NULL, there are no usable indexes and your query may benefit from adding an index to the queried columns. Beware of adding too many indexes as they will add an overhead when to future INSERT/UPDATE/DELETE operations.
MySQL Documentation - Explain possible keys
used_key_partsβ
Composite indexes are just indexes on multiple columns. used_key_parts
shows which part of a multiple column key is being used.
key_lengthβ
The key_length
column shows the length of the key the planner picked for the query. This shows if only part of a multiple part key was used.
If key
is NULL then key_length
will be NULL and no suitable index was found.
MySQL Documentation - Explain key_len
used_columnsβ
List of columns of the table (per each table in the query block) used for either read or write in the query. If the number of columns inΒ used_columns
is reasonably small, you can use it as a guide for creating a covered index.
refβ
The ref
column in the query block shows which columns or constants are compared with the key
column to select rows. If func
is returned, then a function or arithmetic operator is being used.
MySQL Documentation - Explain ref
Additional Linksβ
Search onlineβ
If this article doesn't have the information you need you can try searching online. Remember, you can contribute suggestions to this page.