where execution order of SQL
1 MySQL from left to right.
A principle that excludes the more conditions put to the first one
Example: Copy the.
SELECT ... WHERE p.languages_id = 1 and m.languages_id = 1 and c.languages_id = 1 and t.languages_id = 1 and p.products_id in (472,47 4)
This makes the query take more than 20 seconds, although indexes are established on each field. Using the analysis of explain SQL, we found that tens of thousands of data were returned during the first analysis:
WHERE p.languages_id = 1, and then, in turn, narrows the range by condition.
And I changed the location of the where field, and there was a noticeable increase in speed:
WHERE p.products_id in (472,474) and
p.languages_id = 1 and m.languages_id = 1 and c.languages_id = 1 and t.languages_id = 1
Thus, the first condition is p.products_id in (472,474), it returns less than 10 results, followed by other conditions to filter, natural speed has a greater increase.
2 orcal
From right to left
where execution order of SQL