Should I COUNT(*) or not?

前端 未结 14 1649
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-30 15:49

I know it\'s generally a bad idea to do queries like this:

SELECT * FROM `group_relations`

But when I just want the count, should I go for this

14条回答
  •  清歌不尽
    2021-01-30 16:37

    COUNT(*) facts and myths:

    MYTH: "InnoDB doesn't handle count(*) queries well":

    Most count(*) queries are executed same way by all storage engines if you have a WHERE clause, otherwise you InnoDB will have to perform a full table scan.

    FACT: InnoDB doesn't optimize count(*) queries without the where clause

提交回复
热议问题