mysql time index execution plan

Project query time off data discovery query time is very long. No doubt take the index time, so explain what

EXPLAIN select * from t_order where created_at>'2015-01-01 00:00:00' and created_at<'2017-01-01 00:00:00'

 

Resolution:

id:

Expressed order of execution, the id values ​​are the same, the execution order is from top to bottom, the id values ​​are different, the larger the value of id, higher priority, the first execution

select_type:

1, SIMPLE said they did not contain sub-queries and union

2, if the query contains a subquery, the outermost query is marked as: PRIMARY

3, included in the select list or where the sub-queries, they are marked: SUBQUERY

4, sub-queries from would mark: DERIVED 

5, selcect result is out of the union flag is: UNION RESULT

type:

He expressed the need to find the type of access line

ALL,index,range,ref,eq_ref,const,system,NULL

Performance from worst to best

key:

Indicate which index to use

From the screenshot above to see did not go create_at index.

 

Information found on the Internet:

When the index table being queried, the best use of the index, unless the optimizer uses a full table scan is more effective. Optimization best optimization index sake check out the table exceeds 30% of the data depends on the use of table scan data. 
The optimizer is more complex, which is estimated based on other factors, in Table size, number of rows and the I / O block size.

 


I found the reason:
the data using the count of the entire table, and conditions have been found more than 30% ,, so ineffective. When indexing, to be established according to the column base. Column cardinality column different data = / divided by the total data. The closer to 1 indicates
the less duplication, more suitable for indexing.

 

solve:

According to the above theory, the scope of time off query by order number. Differentiating the time since the order number, and a column base = 1;

Guess you like

Origin www.cnblogs.com/fanblogs/p/11223873.html