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.