How to speed up “select count(*)” with “group by” and “where”?

后端 未结 9 533
北恋
北恋 2020-12-07 10:28

How to speed up select count(*) with group by?
It\'s too slow and is used very frequently.
I have a big trouble using select count(*)

9条回答
  •  既然无缘
    2020-12-07 10:50

    I see that a few individuals have asked what engine you were using for the query. I would highly recommend you use MyISAM for the following reasions:

    InnoDB - @Sorin Mocanu properly identified that you will do a full table scan regardless of indexes.

    MyISAM - always keeps the current row count handy.

    Lastly, as @justin stated, make sure you have the proper covering index:

    CREATE INDEX ix_temp ON relations (relation_title, object_title);
    

提交回复
热议问题