Mysql execution scheduler _ MySQL

Source: Internet
Author: User
Mysql execution plan bitsCN.com bad SQL not only directly affects the SQL response time, but also affects the database performance, resulting in a longer response time for other normal SQL statements. It is vital to learn how to write SQL statements and view execution plans. The following is a brief description of the mysql execution plan, which only lists some common situations and hopes to help you. Test TABLE structure: create table 'T1' ('C1 'Int (11) not null default '0', 'C2 'varchar (128) default null, 'C3' varchar (64) default null, 'C1' int (11) default null, primary key ('C1'), KEY 'IND _ C2' ('C2 '), KEY 'IND _ Cid' ('CID') ENGINE = InnoDB default charset = utf8 create table 'T2' ('C1' int (11) not null default '0 ', 'C2 'varchar (128) default null, 'C3' varchar (64) default null, 'C1' int (11) default null, PRIMARY KEY ('C1 '), KEY 'IND _ c2' ('C2 ') ENGINE = InnoDB default charset = utf8 create table 't3' ('C1 'int (11) not null default '0', 'C2 'varchar (128) default null, 'C3' varchar (64) default null, 'C1' int (11) default null, primary key ('C1 '), KEY 'IND _ c2' ('C2 ') ENGINE = InnoDB default charset = utf8 1. view mysql execution plan explain select ...... 2. information contained in the execution plan (1 ). id, indicating the order of select statements or operation tables. Eg1: the id is the same. the execution sequence is from top to bottom. the following execution plan indicates that table t1 is operated first, table t2 is operated, and table t3 is finally operated. Eg2: if a subquery exists, the id of the subquery (inner query) is greater than that of the parent query (outer query). the subquery is executed first. The higher the id, the higher the priority. (2 ). select_type meaning: select statement Type:. SIMPLE: the query does not contain a subquery or UNIONb. if the query contains any complicated child parts, the outermost query is marked as PRIMARYc. the SELECT or WHERE list contains a subquery marked as SUBQUERYd. the subquery contained in the FROM list is marked as DERIVED (derivative) e. if the second SELECT clause appears after UNION, it is marked as UNION. if UNION is included in the subquery of the FROM clause, the outer SELECT is marked as DERIVEDf. the SELECT statement for obtaining results from the UNION table is marked as: UNION RESULTeg: the table with id 1 is displayed. , Indicating that the result is derived from derivative table 2. If id is 2, it indicates a subquery. if the id of table t3 is 3, it is union, which is the second select of union, and is executed first. if id is NULL, it is union result, The result set of an operation with id 1 and an operation with id 3. Execution sequence 3-> 2-> 1-> NULL (3). meaning: the method used to obtain the record row, that is, the mysql access method. A. ALL: Full Table Scan. MySQL will traverse the entire Table to find the matched row B. index: Full Index Scan. The difference between index and ALL is that the index type only traverses the index, and the Index is generally smaller than the record. Because the index contains c1, c1 and c2 can be queried through index scanning. C. range: index range scan. an index scan starts at a certain point and returns rows that match the value range. it is common in between, <,>, and other queries. note: the range type must use index scanning; otherwise, the type is ALL d. ref: non-unique index scan. all rows matching a single value are returned. T2.c4 is a non-unique index. e. eq_ref: it is a unique index scan. each index Key has only one record matching it. Common primary key or unique index scanning t2.c1 is the primary key index, and the primary key index is also the unique index f. const and system: These types of access are used when MySQL optimizes a part of the query and converts it to a constant. For example, if the primary key is placed in the where List, MySQL can convert the query to a constant. system is a special case of the const type. when the queried table has only one row, use system (4 ). possible_keys: indicates which index MySQL can use to find rows in the table. if an index exists in the fields involved in the query, the index is listed, but not necessarily used for query (5 ). key

Description: displays the indexes actually used by MySQL in the query. If no index is used, it is NULL.

(6) key_len

Description: The number of bytes used in the index. you can use this column to calculate the length of the index used in the query.

(7) ref

Description: used for connection query. it indicates that a column in a specific table is referenced.

(8) rows

Meaning: MySQL estimates the number of rows to be read from the required records based on the table Statistics and index selection. this value is inaccurate and only serves as a reference.

(9) Extra

Meaning: displays additional auxiliary information.

A. Using index indicates that the index is used.

B. Using where, which indicates filtering by the where condition

C. Using temporary, indicating that a temporary table is used, which is common in grouping and sorting.

D. Using filesort, indicating that index sorting cannot be used and files need to be sorted.

Eg1: the t1.c3 column has no index.

Eg2: use the index column t1.c2

BitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.