主頁 > 知識(shí)庫 > where 子句的執(zhí)行順序

where 子句的執(zhí)行順序

熱門標(biāo)簽:呼叫中心市場需求 地方門戶網(wǎng)站 Linux服務(wù)器 AI電銷 百度競價(jià)排名 服務(wù)外包 鐵路電話系統(tǒng) 網(wǎng)站排名優(yōu)化
看代碼:
復(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)行排序的語句。

標(biāo)簽:衡水 蘭州 崇左 湘潭 仙桃 銅川 黃山 湖南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《where 子句的執(zhí)行順序》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266