SQLServer CASE表达式

编程入门 行业动态 更新时间:2024-10-13 00:35:10
本文介绍了SQLServer CASE表达式-短路评估?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试优化执行以下操作的查询:

I am trying to optimize a query that does something like this:

SELECT ... CASE WHEN (condition) THEN (expensive function call #1) ELSE (expensive function call #2) END ...

查询计划表明,即使在100%的行满足WHEN子句的情况下,ELSE分支中也有相当一部分时间用于结果调用.

The query plan shows that for even in cases where 100% of rows satisfy the WHEN clause, a substantial portion of the time is spent in calls to the result in the ELSE branch.

我能理解的唯一方法是假定SQLServer正在评估两个结果,然后仅基于对WHEN条件的评估来选择一个,但是我找不到关于结果是否是否有任何明确的参考在条件语句之前先评估CASE语句的.任何人都可以澄清或指向我参考吗?

The only way I can make sense of this is to presume that SQLServer is evaluating both results, then only selecting one based on evaluation of the WHEN condition, but I can't find any definitive reference as to whether or not the results of a CASE statement are evaluated before the conditionals. Can anyone please clarify or point me to a reference?

推荐答案

这是实际计划还是估计计划? Sql Server根据收集到的统计数据期望执行的计划来构建计划,而这并不总是与您为查询运行的一个实例发送给它的特定条件相对应.

Is that an actual or estimated plan? Sql Server builds plans based on what it expects to do based on collected statistics, and that doesn't always jibe with what specific conditions you send it for one instance of a query run.

更多推荐

SQLServer CASE表达式

本文发布于:2023-11-12 10:27:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   SQLServer   CASE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!