Home > Database > Mysql Tutorial > body text

MySQLSQL优化:关联子查询的局限性_MySQL

WBOY
Release: 2016-06-01 13:17:37
Original
965 people have browsed it

这是MySQL SQL优化的第三篇。公司某个业务系统频繁抛出问题SQL,我们对此类SQL做了基本面统计:

此类SQL近期共执行了12次,最长一次花费480秒,最短286秒

t1表的rows有90多万,始终会扫描这么多不需要的数据

这是由于MySQL查询优化器在处理相关子查询方面存在局限性

MySQL总是会将相关的外层表压到子查询中,它认为这可以更高效地查找数据行。

如果是个小表,情况可能还不会引起我们注意,但是如果外层表示一个非常大的表,那么这个查询的性能会非常槽糕,

很不幸,我们的场景刚好应了后者

我们优化后的执行效果:

 Good Luck!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!