【Oracle】Count(*)、Count(1)、Count(rowid)的对比
看了这篇评测后http://www.cnoug.org/viewthread.php?tid=857&page=1,再也不用对Count(*)、Count(1)、Count(rowid)烦恼性能高低了。
从这个帖子抽取的结果
before analyze ,loop 1000,/*+hints*/count(*) :71
before analyze ,loop 1000,count(*) :70
before analyze ,loop 1000,count(1) :71
before analyze ,loop 1000,count(rowid) :113
before analyze ,loop 1000,count(id) :72
before analyze ,loop 1000,count('a') :72
before analyze ,loop 1000,count(null) :103
before analyze ,loop 1000,count(*) :70
before analyze ,loop 1000,count(1) :71
before analyze ,loop 1000,count(rowid) :113
before analyze ,loop 1000,count(id) :72
before analyze ,loop 1000,count('a') :72
before analyze ,loop 1000,count(null) :103
结果很明显,Count(*)、Count(id)、Count(常量)最快,Count(rowid)最慢
对于Oracle来说,应该是Count(id)最快,而Oracle自身很有可能把Count(*)优化成Count(id)来执行
其实用Count(*)就行了,简单!Oracle自身已经对某些语句优化过了。