Home > Database > Mysql Tutorial > Mysql SQL性能优化之order_MySQL

Mysql SQL性能优化之order_MySQL

WBOY
Release: 2016-06-01 13:36:16
Original
978 people have browsed it

bitsCN.com

Mysql SQL性能优化之order

 

mysql的order在排序时,会被select出来的数据多少所影响,

数据列越多,排序越慢,为了说明这个问题,请看几个例子。

高效的查询

低性能:

 

select id,job_name from test_results where id

1 rows fetched (390 ms)

 

高性能:

 

select id,job_name from test_results where id =(select id from test_results where id

1 rows fetched (281 ms)

 

高效的分页查询  www.bitsCN.com  

低性能:

 

select id,job_name from test_results order by id desc limit 1200000,100;

100 rows fetched (34.616 sec)

 

高性能:

 

select id,job_name from test_results join (select id from test_results order by id desc limit 1300000,100) as t2 using(id);

100 rows fetched (5.460 sec)

 

接下来我们分析其原因,首先从mysql的执行顺序开始讲起,

执行顺序从上到下:

FROM

ON

JOIN

WHERE

GROUP BY

HAVING

SELECT

DISTINCT

ORDER BY

 

所以得出结论,select出来的数据越多,排序越慢。

减少了order by中的排序数据,再去join或者=查询即可加快执行效率。

 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template