Execution order of WHERE clause _ database other

Source: Internet
Author: User
Look at the code:
Copy Code code as follows:

SET STATISTICS IO on
Set STATISTICS TIME on
Go
Set STATISTICS PROFILE on
Go

Use pubs
SELECT * FROM Authors
Where (au_fname like ' s% ' or au_fname like ' a% ')
and (state like ' CA ' or state like ' UT ')
and (cast (zip as int) > 90000)

SELECT * FROM Authors
Where (au_fname like ' s% ' or au_fname like ' a% ')
and (cast (zip as int) > 90000)
and (state like ' CA ' or state like ' UT ')

SELECT * FROM Authors
where (cast (zip as int) > 90000)
and (au_fname like ' s% ' or au_fname like ' a% ')
and (state like ' CA ' or state like ' UT ')

Purpose: To verify the query order of the various conditions of the WHERE statement
Environment: SQL Server 2005Express version
Step: Show Query plan
Results: Without exception, they were unified into such code.
Copy Code code as follows:

|--clustered Index Scan (OBJECT: ([pubs].[ DBO]. [authors]. [UPKCL_auidind]), Where: (CONVERT (int,[pubs].[ DBO]. [authors]. [zip],0) > (90000) and ([pubs].[ DBO]. [authors]. [au_fname] like ' s% ' OR [pubs]. [dbo]. [authors]. [au_fname] like ' a% ') and ([pubs].[ DBO]. [authors]. [State] like ' CA ' OR [pubs]. [dbo]. [authors]. [State] (like ' UT '))

Conclusion: In the version before 2005, the order of the WHERE clause is from the post. But it looks like it was optimized in the 2005 version, and all of the sequences were unified into statements that sorted by filtering capabilities.

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.