Mysql execution plan analysis:
MySQL execution plan EXPLAIN can mainly be analyzed by type:
select_type represents the type of each select clause in the query (simple OR complex)
a.SIMPLE: The query does not contain subqueries or UNIONs b. If the query contains any complex subsections, the outermost query is marked as: PRIMARY c. A subquery is included in the SELECT or WHERE list, and the subquery is marked as: SUBQUERY d. Subqueries contained in the FROM list are marked as: DERIVED e. If the second SELECT appears after UNION, it is marked as UNION; if UNION is included in the subquery of the FROM clause, the outer SELECT will be marked as: DERIVED f. The SELECT that gets the result from the UNION table is marked as: UNION RESULT
type indicates the way MySQL finds the desired row in the table, also known as "access type". The common types are as follows: (from top to bottom, the effect becomes better in turn)
ALL:Full Table Scan。 index:Full Index Scan。 range: Index range scan. ref : Non-unique index scan. eq_ref : Unique index scan. const,system: Convert the query to a constant. null: MySQL decomposes the statement during optimization and executes it without even accessing the table or index
All : full table scan, no index is used range: index range scan, the scan of the index starts at a certain point, and returns rows that match the value range, commonly used in queries such as between, <, >, IN, etc. ref: A non-unique index scan that returns all rows matching a single value. eq_ref: Unique index scan, for each index key, only one record in the table matches it. const, system: These types are used when MySQL optimizes a part of the query and converts it to a constant. If the primary key is placed in the where list, MySQL can convert the query into a constant. system is a special case of const type. When the query table has only one row, use system. NULL: MySQL decomposes the statement during optimization and executes it without even accessing the table or index.
如:explain select * from account_balance where userid='123'