What happend first in mysql: join or where

前端 未结 1 1462
不思量自难忘°
不思量自难忘° 2021-02-15 11:43

Let\'s say I have two tables A and B and the following query:

select *
from A
inner join B on A.id = B.id
Where A.id = 5

Does mysql first perfo

相关标签:
1条回答
  • 2021-02-15 12:19

    The join happens before the where, however...

    The where clause is a filter for all rows returned by the join, but the optimizer will recognise that if an index exists on A.id, it will be used to retrieve rows from A that match, then the join will happen, then theoretically the where clause will filter the results, but again the optimizer will recognise that the condition will already be met so it will skip it as a filter.

    All that said, the optimizer will always return the same result as would be returned without the optimizer.

    0 讨论(0)
提交回复
热议问题