现代DBMS包括短路布尔评估? [英] Do modern DBMS include short-circuit boolean evaluation?

查看:109
本文介绍了现代DBMS包括短路布尔评估?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多现代编程语言具有短路布尔型评估,如下所示:

  if(x()OR y ))



如果 x()返回true , y()从不评估。



现代DBMS(SQL Server,Sybase,Oracle,DB2等)上的SQL是否具有此属性? b

特别是如果布尔语句的左边是布尔常数,它是否会短路?






相关:所有的编程语言都有boolean short - 电路评估?

解决方案

专门针对SQL Server -



您指定OR语句的顺序不能保证短路,因为优化器可以重新排序它们,如果感觉更好的性能增益可以这样做。



但是,底层引擎本身可以并且会短路。



以下文章(链接到其他出色的讨论/资源)有更多关于此主题的内容: http://weblogs.sqlteam.com/jeffs/archive/ 2008/02/22 / sql-server-short-circuit.aspx


Many modern programming languages have short-circuit boolean evaluation such as the following:

if (x() OR y())

If x() returns true, y() is never evaluated.

Does SQL on modern DBMS (SQL Server, Sybase, Oracle, DB2, etc) have this property?

In particular if the left side of the boolean statement is a boolean constant, will it be short circuited?


Related: Do all programming languages have boolean short-circuit evaluation?

解决方案

Speaking specifically for SQL Server - sort of.

The ordering in which you specify your OR statements can't guarantee short-circuiting because the optimizer can re-order them at-will if it feels better performance gains can be made by doing so.

However, the underlying engine itself can and will short-circuit. It's just something that the user can't control.

The following article (which links to other excellent discussions/resources) has more on this topic: http://weblogs.sqlteam.com/jeffs/archive/2008/02/22/sql-server-short-circuit.aspx

这篇关于现代DBMS包括短路布尔评估?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆