Is there any idea to optimize this sql that it takes several minutes to count 11M rows ?Any ideaes, I will be very grateful.
mysql version : 5.7.15-log
explain SELECT count(id) FROM consumer.class:
it responsed
Select tables optimized away
(not use any index ,It seems that the mysql querier is automatically optimized,but it is too slow!!)
then i use force index(primary)
,I get the same result,If i want use force index,I must add where id > 0
,Run with the sql of
SELECT count(`id`) FROM `consumer`.`class` force INDEX (`id`)
will not use the index too,It is no effect,only like this can use the force index:
Even if the use of the index, the query also takes a few minutes, and sometimes can not even get mysql return. This is unacceptable
show profile(this picture is reduced to 200,000 rows results,31M can not get mysql's response):
I found that "Sending data" operate use a lot of time,But I don't know how to optimize.