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

后端 未结 9 519
北恋
北恋 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:52

    test count(myprimaryindexcolumn) and compare performance to your count(*)

    0 讨论(0)
  • 2020-12-07 10:55

    I would suggest to archive data unless there is any specific reason to keep it in the database or you could partition the data and run queries separately.

    0 讨论(0)
  • 2020-12-07 11:03

    If you what the size of the whole table, you should query the meta tables or info schema (that exist on every DBMS I know, but I'm not sure about MySQL). If your query is selective, you have to make sure there is an index for it.

    AFAIK there is nothing more you can do.

    0 讨论(0)
提交回复
热议问题