[ORACLE]杀死伪科学──也谈count(*)和count(1) (
来源:互联网 发布:js模仿php获取参数 编辑:程序博客网 时间:2024/06/15 21:52
[ORACLE]杀死伪科学──也谈count(*)和count(1)
(2011-09-01 09:43:13)oracle
count
杂谈
分类: Oracle在部门里发现有一些工程师热衷于使用count(1)或者count(0)之类的聚合查询,用“一些”可能还有点保守。曾经问过几个工程师count(1)与count(*)到底有什么区别,有的说count(1)比count(*)快,还有一个说等你实际碰到问题时就知道count(1)的优势了!有一次我在群里面讨论一个技术问题,用到了count(*)查询,当时就有一个同事说使用count(1)这是常识,当时我就汗颜了,搞了这么长时间数据库,原来我连常识都不知道!
我始终坚持在代码中使用count(*),因为我经过自己的实验没有发现count(1)比count(*)有任何优点,而那些听说count(1)比count(*)更高效的工程师,无一能够说出具体的原因来,这成了一个美丽的传说!不过我也发现了一个问题,热衷于count(1)的工程师基本上是工作1年左右或者未满1年的,我从没有听说哪个数据库专家或者DBA说过count(1)比count(*)更好的理论。
在网上也查了一些针对count(*)与count(1)的实验,但是没有一个能说清楚个所以然的,有的甚至用执行时间去衡量二者的好坏,这个有点太不专业了!
最后,我只能搬出TOM他老人家来说明count(*)和count(1)真的没什么差别,别在坚持这个谬论了!引用如下:
You Asked
What is the difference between count(1) and count(*) in a sql query
eg.
select count(1) from emp;
select count(*) from emp;
and we said...
nothing, they are the same, incur the same amount of work -- do the same thing, take the
same amount of resources.
具体解释请自行阅读:http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1156159920245
- [ORACLE]杀死伪科学──也谈count(*)和count(1) (
- Oracle count(1) count(*) count(col)
- count(column) 和 count(*)和count(1)
- count(*),count(1)和count(field)区别
- 【数据库】count(*),count(1)和count(列)
- count(*),count(1)和count(field)区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- Oracle 中count(1) 和count(*) 的区别
- 关于count(1)和count(*)
- count(),count(1),count(*)
- oracle中关于count(1)、count(*)、count(rowid)、count(某个字段)使用上的区别和性能问题
- oracle中关于count(1)、count(*)、count(rowid)、count(某个字段)使用上的区别和性能问题
- oracle sql count(1)与count(*)
- 常见浏览器兼容性问题与解决方案
- C++基础之动态分配内存
- WPF 详解模板
- Js Event Loop
- 该版本的 %1 与您运行的 Windows 版本不兼容
- [ORACLE]杀死伪科学──也谈count(*)和count(1) (
- 抽象类及接口(两者的区别)
- href="#"不跳转到页面顶端
- poj 1088 滑雪(记忆化搜索 || DP)
- 技术只是谋生手段,不是赚钱的终点,但是没有技术你连立身之处都没有
- BeanFactory not initialized or already closed - call 'refresh' before access
- Mysql里查询字段为Json格式的数据模糊查询方法
- Linux_Centos_rz(上传) /sz(下载) 指令安装
- Android Camera2 API Explained