Does table order matter in mysql?

Or will the optimizer choose this for you?

For instance,

SELECT * FROM t1 JOIN t2 USING (id)

Same as

SELECT * FROM t2 JOIN t1 USING (id)
+3
source share
2 answers

For internal joins, order does not matter.

For external connections, order matters.

If you want to force a certain order, you can use STRAIGHT_JOIN.

+8
source

explain

In your case, the query planner should always be able to understand this. But sometimes it’s not always that simple.

If you really want to know how the request will be executed, enter explainbefore the request:

explain SELECT * FROM t2 JOIN t1 USING (id);

, "" .

+1

Source: https://habr.com/ru/post/1776329/


All Articles