optimize mysql count query

后端 未结 10 627
忘了有多久
忘了有多久 2020-12-30 05:54

Is there a way to optimize this further or should I just be satisfied that it takes 9 seconds to count 11M rows ?

devuser@xcmst > mysql --user=user --pass         


        
10条回答
  •  醉梦人生
    2020-12-30 06:10

    Instead of doing count(*), try doing count(1), like this:-

    select count(1) from record_updates where date_updated > '2009-10-11 15:33:22'
    

    I took a DB2 class before, and I remember the instructor mentioned about doing a count(1) when we just want to count number of rows in the table regardless the data because it is technically faster than count(*). Let me know if it makes a difference.

    NOTE: Here's a link you might be interested to read: http://www.mysqlperformanceblog.com/2007/04/10/count-vs-countcol/

提交回复
热议问题