My sql explain cheat sheet

  • 728 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
728
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
13
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Syntax: EXPLAIN <SELECT STATEMENT>Explain Column Definitionsid A sequential IDselect_type See SELECT_TYPEtable The table or aliastype See TYPEpossible_keys The possible indexes that could be usedkey The actually index usedkey_len See KEY_LENref The columns (or constants) usedrows Approximate # of rows returnedExtra See EXTRAEXTRAconst row not found The table was emptyDistinct Stops after first matching rowFull scan on NULL key No index lookup on a subqueryImpossible HAVING HAVING is always falseImpossible WHERE WHERE is false for all rowsImpossible WHEREnoticed after readingconst tablesWHERE is false for all rows after const (and system)tables have been readNo tables used No FROMNot exists LEFT JOIN optimization. Stops after first row matchRange checked for eachrecord (index map: N)No good index found. One might be available as queryis processedSelect tablesoptimized awayOnly aggregate functions that can be resolved using anindexUsing filesort Sorting was needed rather than using an indexUsing temporary During execution a temporary table was requiredUsing index The query was satisfied using only an indexUsing where A WHERE clause existsUsing index for group-byGROUP BY or DISTINCT query can be satisfied withan indexUsing sort_union(...),Using union(...),Using intersect(...)index_merge join typeUsing join buffer Join was performed using an internal bufferKEY_LENtinyint 1 byte TIMESTAMP 4 bytessmallint 2 bytes DATETIME 8 bytesINT 4 bytes CHAR(n) n bytesBIGINT 8 bytes VARCHAR(n) n bytes + 2 bytesDATE 3 bytes NULL possible +1 byteWarning! Multibyte characters make byte!=character. UTF8 is 3 bytesSELECT_TYPESIMPLE Simple SELECTPRIMARY First SELECT in a UNION or outer query in asubqueryUNION Second or later SELECT in a UNIONDEPENDENT UNION Second or later SELECT in a UNIONdependent on outer queryUNION RESULT Result of a UNIONSUBQUERY First SELECT in a subqueryDEPENDENTSUBQUERYFirst SELECT in a subquery. It is dependenton an outer variableDERIVED Derived table. SELECT subquery in FROMclauseUNCACHEABLESUBQUERYResult of subquery must be re-evaluated foreach other query rowTYPEsystem The table has only one value (a system table)const Exactly one matching row using PRIMARY or UNIQUEeq_ref One row is matched from this table for each combination of rowsfrom the previous tables.ref All matching rows from this table for each combination of rowsfrom the previous tables.fulltext FULLTEXT index is usedref_or_null ref with an additional pass for NULL valuesindex_merge Index merge optimization usedunique_subquery Optimized subquery handling in queries of the form value IN(SELECT …) using PRIMARY or UNIQUE keysindex_subquery Like unique_subquery but with non-unique indexesrange KEY is compared against =, <>, >, >=, <, <=, ISNULL, <=>, BETWEEN, or IN()index Same as ALL but only the index is scannedALL Full table Scan