The Optimizer in 4.1 is weird. When doing joins, I expect it to
figure out how to pick which tables to lookup 1st and compare in
a correct manor. My expectations is a bit to much.
For instance say you have table:
-
- A with 1 million rows
- B with 10 million rows
- C with 100 million rows
So, doing a small range on table A and taking these results to
filter out with the other tables I expect the join order to
be
A, B, C
Yet, the mySQL optimizer in many cases will join the table in the
order of
B, A, C.
This is wrong. I know that the range generated from A is smaller
then the range generated from B.
To get around this I use STRAIGHT_JOIN in a global context
SELECT STRAIGHT_JOIN SQL_CALC_FOUND_ROWS A.*, B.*, …
[Read more]