欢迎光临
我们一直在努力

where 子句的执行顺序

看代码:

复制代码 代码如下:


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语句的各个条件的查询顺序
环境:SQLServer 2005Express版本
步骤:显示查询计划
结果:无一例外,都被统一成了这样的代码

复制代码 代码如下:


|–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\’)))


结论:貌似在2005之前的版本中,where子句的顺序是从前往后的。但是又貌似在2005的版本中进行了优化,所有的顺序都被统一成了以过滤能力进行排序的语句。

赞(0) 打赏
主机商所有内容均来自网络,若无意侵犯到您的权利,请及时与联系 QQ 2232175042,将在48小时内删除相关内容!!主机测评网 » where 子句的执行顺序

主机商评测网 找服务器 更专业 更方便 更快捷!

专注IDC行业资源共享发布,给大家带来方便快捷的资源查找平台!

联系我们

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫