where execution order of SQL

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.