Home > Database > Mysql Tutorial > [MySQLView]最有意思的视图view优化过程,从30分钟到0.08秒_MySQL

[MySQLView]最有意思的视图view优化过程,从30分钟到0.08秒_MySQL

WBOY
Release: 2016-06-01 13:18:10
Original
1175 people have browsed it

bitsCN.com

开发人员写了一个view,select要30分钟,让我优化下,view如下:

开发人员select一下需要30多分钟:

21068 rows in set (1987.08 sec)

先解析一下:

mysql> explain SELECT `ol`.`OFFER_ID` AS `OFFER_ID`,`ol`.`EFFECTIVE_DATE` AS `EFFECTIVE_DATE`

看到有 Using filesort,要优化where后面的子判断,优化如下:

select max(ol2.ID)

有些不对劲,再仔细看了view的结构,恍然大悟:

优化成如下样子:

CREATE ALGORITHM=UNDEFINED SQL SECURITY DEFINER VIEW view_offer_label AS

执行结果为:

21068 rows in set (0.08 sec)

不到0.08秒,数据完全正确。

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