where 子句的執(zhí)行順序
更新時間:2009年04月05日 00:35:02 作者:
貌似在2005之前的版本中,where子句的順序是從前往后的。但是又貌似在2005的版本中進行了優(yōu)化,所有的順序都被統(tǒng)一成了以過濾能力進行排序的語句。
看代碼:
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')
目的:想驗證where語句的各個條件的查詢順序
環(huán)境:SQLServer 2005Express版本
步驟:顯示查詢計劃
結(jié)果:無一例外,都被統(tǒng)一成了這樣的代碼
|--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')))
結(jié)論:貌似在2005之前的版本中,where子句的順序是從前往后的。但是又貌似在2005的版本中進行了優(yōu)化,所有的順序都被統(tǒng)一成了以過濾能力進行排序的語句。
復(fù)制代碼 代碼如下:
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')
目的:想驗證where語句的各個條件的查詢順序
環(huán)境:SQLServer 2005Express版本
步驟:顯示查詢計劃
結(jié)果:無一例外,都被統(tǒng)一成了這樣的代碼
復(fù)制代碼 代碼如下:
|--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')))
結(jié)論:貌似在2005之前的版本中,where子句的順序是從前往后的。但是又貌似在2005的版本中進行了優(yōu)化,所有的順序都被統(tǒng)一成了以過濾能力進行排序的語句。
相關(guān)文章
遠程數(shù)據(jù)庫的表超過20個索引的影響詳細解析
這篇文章主要介紹了遠程數(shù)據(jù)庫的表超過20個索引的影響詳細解析,具有一定參考價值,需要的朋友可以了解下。2017-10-10Sql Server、Access數(shù)據(jù)排名的實現(xiàn)方法(例如:成績排名)
在很多時候,我們需要統(tǒng)計數(shù)據(jù)的排名情況,最常見的是成績、投票數(shù)等等的。2009-06-06SQLite不支持Right Join的解決辦法GROUP BY
sqlite真的不錯,就是不支持right join,所以我們用下面的方法解決2008-06-06