Heim  >  Artikel  >  Datenbank  >  MySQLSQL优化:关联子查询的局限性_MySQL

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

WBOY
WBOYOriginal
2016-06-01 13:17:37971Durchsuche

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

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

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

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

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

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

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

我们优化后的执行效果:

 Good Luck!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn