“SELECT COUNT(*)” is slow, even with where clause

后端 未结 8 1635
抹茶落季
抹茶落季 2020-11-30 23:22

I\'m trying to figure out how to optimize a very slow query in MySQL (I didn\'t design this):

SELECT COUNT(*) FROM change_event me WHERE change_event_id >         


        
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 23:58

    MySQL does say "Using where" first, since it does need to read all records/values from the index data to actually count them. With InnoDb it also tries to "grab" that 4 mil record range to count it.

    You may need to experiment with different transaction isolation levels: http://dev.mysql.com/doc/refman/5.1/en/set-transaction.html#isolevel_read-uncommitted

    and see which one is better.

    With MyISAM it would be just fast, but with intensive write model will result in lock issues.

提交回复
热议问题