Does the order of the column name assignation in the join part have an impact on indexes ?
For example, if I have an index on table X column Y, and I write:
SELECT * FROM B LEFT JOIN X ON X.Y = B.Y
Then the Y index from table X is used. However, if I write the same query like this:
SELECT * FROM B LEFT JOIN X ON B.Y = X.Y
will the index still be used?
Best Answer
In general, no. Inner and Outer joins are not affected by the order tables and columns in the query. This can be confirmed by the result of
explain
as @ypercube mentioned.However, if you join using "STRAIGHT_JOIN", then the order of the tables (not the columns) does matter.
Example: