的mysql,ifnull vs合并,哪个更快? [英] mysql, ifnull vs coalesce, which is faster?

查看:224
本文介绍了的mysql,ifnull vs合并,哪个更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果已知只有两个值可用于列结果,

if it's known that there are only two values to candidate for the result of a column,

ifnull(a, b) as a_or_b_1

coalesce(a, b) as a_or_b_2

将给出相同的结果.但是哪个更快?搜索时,我发现本文,其中说 ifnull 更快.但这是我发现的唯一文章.有什么看法吗?

will give the same result. but which is faster? when searching i found this article, which says ifnull is faster. but it was the only article i found. any views on this?

提前感谢:)

推荐答案

我的观点是您应该对使用情况进行基准测试.

My view is that you should benchmark for your usage.

我怀疑会有很大的不同. 请记住,虽然一个基准可能暗示一个基准会稍好一些,但随着时间的推移数据的变化可能会改变结果.

I doubt there will be much difference. Bear in mind that while a single benchmark might suggest that one is slightly better, variation in the data over time might change that result.

还请注意,自1992年以来,COALESCE一直是标准SQL的一部分-我不确定IFNULL是否在任何标准中.

Also note that COALESCE has been part of standard SQL since 1992 - I'm not sure IFNULL is in any standard yet.

Adam Machanic有一篇不错的文章,介绍了对等效方案进行基准测试- 性能: ISNULL vs. COALESCE (在SQL Server中).请注意有关获得有效测试的一些条件.

There's a nice article by Adam Machanic about benchmarking an equivalent scenario - Performance: ISNULL vs. COALESCE (in SQL Server). Note some of the provisos on getting a valid test.

这篇关于的mysql,ifnull vs合并,哪个更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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