Is there a way to force MySQL execution order?

送分小仙女□ 提交于 2019-12-01 02:44:00
Hammerite

Perhaps you need to use STRAIGHT_JOIN.

http://dev.mysql.com/doc/refman/5.0/en/join.html

STRAIGHT_JOIN is similar to JOIN, except that the left table is always read before the right table. This can be used for those (few) cases for which the join optimizer puts the tables in the wrong order.

You can try rewriting in two ways

  • bring some of the WHERE condition into JOIN
  • introduce subqueries even though they are not necessary

Both things might impact the planner.

First thing to check, though, would be if your stats are up to date.

You can use FORCE INDEX to force the execution order, and I've done that before.

If you think about it, there's usually only one order you could query tables in for any index you pick.

In this case, if you want MySQL to start querying a first, make sure the index you force on b is one that contains b.table1_id. MySQL will only be able to use that index if it's already queried a first.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!