區(qū)別
count(*):所有行進(jìn)行統(tǒng)計(jì),包括NULL行
count(1):所有行進(jìn)行統(tǒng)計(jì),包括NULL行
count(column):對(duì)column中非Null進(jìn)行統(tǒng)計(jì)
性能
性能實(shí)際上差不多
count(id)的時(shí)候多了一個(gè)Select operator;
count(id)的Group By Operator 的 aggregations過程略有不同
擴(kuò)展
mysql count(1) 和 count(*) 區(qū)別
查詢條件中沒有索引時(shí),count(*)比count(1)查詢速度要快些。
查詢條件中有索引時(shí),count(1)比count(*)查詢速度要快些。