Check the Code:
Copy codeThe Code is 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) & gt; 90000)
Select * from authors
Where (au_fname like's % 'or au_fname like 'a % ')
And (cast (zip as int) & gt; 90000)
And (state like 'CA' or state like 'ut ')
Select * from authors
Where (Stream (zip as int)> 90000)
And (au_fname like's % 'or au_fname like 'a % ')
And (state like 'CA' or state like 'ut ')
Objective: To verify the query sequence of the where statement's conditions
Environment: SQLServer 2005Express
Step: display the query plan
Result: The code is unified as follows:
Copy codeThe Code is 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 versions earlier than 2005, the order of the where clause is as follows. However, it seems that the version 2005 has been optimized, and all the order is unified into statements sorted by filtering capability.