(转自puber yong huang版主)

Controversy about count(*), count(1), count(PK) and count(rowid)
Every 1 out of 100 people using Oracle believes using count(*) is slower than either count( ), count() or count(rowid); 1 out of 1000 believes count(*) is faster than any other (ratio based on personal impression!). Naive reasoning is that count(*) undergoes a full table scan implied by the *, which means all columns in select * from mytable. "Sophisticated" reasoning is that Oracle internally optimizes the SQL statement when you use count(*). This topic has become an FAQ on several Oracle discussion forums and to some, also an annoying dead horse.

But interestingly, Guy Harrison had some research in this subject in his famous Oracle SQL High-Performance Tuning (see pages 204-5). His execution plan in tkprof indicates that count(*) gives a SORT AGGREGATE on 0 rows (i.e. no sort aggregate), while count(0) and count(customer_id) both show SORT AGGREGATE on 5151 rows. Several people and I on an Oracle mailing list performed the same test on both Oracle 8i and 7.3. Nobody has reproduced SORT AGGREGATE on 0 rows. I emailed Guy Harrison about our test but never received any response.

Then another person performed a test checking the statistic "session logical reads" for all these count methods. The number due to all these counts turned out to be exactly the same.

Can we announce this one count faster than others another urban legend?

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-350569/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/9240380/viewspace-350569/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值