where 子句的執(zhí)行順序
更新時(shí)間:2009年04月05日 00:35:02 作者:
貌似在2005之前的版本中,where子句的順序是從前往后的。但是又貌似在2005的版本中進(jìn)行了優(yōu)化,所有的順序都被統(tǒng)一成了以過濾能力進(jìn)行排序的語句。
看代碼:
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')
目的:想驗(yàn)證where語句的各個(gè)條件的查詢順序
環(huán)境:SQLServer 2005Express版本
步驟:顯示查詢計(jì)劃
結(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的版本中進(jìn)行了優(yōu)化,所有的順序都被統(tǒng)一成了以過濾能力進(jìn)行排序的語句。
復(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')
目的:想驗(yàn)證where語句的各個(gè)條件的查詢順序
環(huán)境:SQLServer 2005Express版本
步驟:顯示查詢計(jì)劃
結(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的版本中進(jìn)行了優(yōu)化,所有的順序都被統(tǒng)一成了以過濾能力進(jìn)行排序的語句。
相關(guān)文章
mycat在windows環(huán)境下的安裝和啟動(dòng)
這篇文章主要介紹了mycat在windows環(huán)境下的安裝和啟動(dòng)過程,需要的朋友參考下吧2018-03-03
SQL語句優(yōu)化之JOIN和LEFT JOIN 和 RIGHT JOIN語句的優(yōu)化
在數(shù)據(jù)庫的應(yīng)用中,我們經(jīng)常需要對(duì)數(shù)據(jù)庫進(jìn)行多表查詢,然而當(dāng)數(shù)據(jù)量非常大時(shí)多表查詢會(huì)對(duì)執(zhí)行效率產(chǎn)生非常大的影響,因此我們?cè)谑褂肑OIN和LEFT JOIN 和 RIGHT JOIN語句時(shí)要特別注意2018-03-03
數(shù)據(jù)庫連接池Druid與Hikari對(duì)比詳解
這篇文章主要為大家介紹了數(shù)據(jù)庫連接池Druid與Hikari對(duì)比詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
數(shù)據(jù)庫之SQL注入原理以及過程的簡(jiǎn)單介紹
這篇文章主要介紹了數(shù)據(jù)庫之SQL注入原理以及過程的簡(jiǎn)單介紹,本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
OceanBase自動(dòng)生成回滾SQL的全過程(數(shù)據(jù)庫變更時(shí))
在開發(fā)中,數(shù)據(jù)的變更與維護(hù)工作一般較頻繁,當(dāng)我們執(zhí)行數(shù)據(jù)庫的DML操作時(shí),必須謹(jǐn)慎考慮變更對(duì)數(shù)據(jù)可能產(chǎn)生的后果,以及變更是否能夠順利執(zhí)行,所以本文給大家介紹了數(shù)據(jù)庫變更時(shí),OceanBase如何自動(dòng)生成回滾 SQL,需要的朋友可以參考下2024-04-04

