where-子句的执行顺序

技术教程 2026-01-08 16:22:13 浏览

代码

复制代码 代码如下:

set statistics io onset statistics time ongoset statistics profile ongouse pubsselect * from authorswhere (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 authorswhere (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 authorswhere (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的版本中进行了优化,所有的顺序都被统一成了以过滤能力进行排序的语句。

本文版权声明本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请联系本站客服,一经查实,本站将立刻删除。

发表评论

热门推荐