小编Sur*_*dhu的帖子

MySQL COUNT查询执行时间太长

我有以下查询需要 7 秒才能运行

SELECT COUNT(*) AS `count` 
FROM `yuldi`.`businesses` AS `Business` 
  LEFT JOIN `yuldi`.`businesses_categories` AS `BusinessesCategory` 
    ON (`Business`.`id` = `BusinessesCategory`.`business_id`) 
  LEFT JOIN `yuldi`.`categories` AS `Category` 
    ON (`BusinessesCategory`.`category_id` = `Category`.`id`) 
WHERE `Category`.`slug` = 'building-construction'
Run Code Online (Sandbox Code Playgroud)

当我第二次运行它时需要 160 毫秒。为什么每次第一次运行都需要这么长时间

解释:

| id | select_type | table              | type   | possible_keys                                                                                   | key                                          | key_len | ref      | rows  | Extra                    |
|  1 | SIMPLE      | Category           | const  | PRIMARY,UNIQUE_SLUG,index_lug                                                                   | UNIQUE_SLUG                                  | 302     | const    |     1 | Using index              | …
Run Code Online (Sandbox Code Playgroud)

mysql performance count mysql-5.5 query-performance

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

count ×1

mysql ×1

mysql-5.5 ×1

performance ×1

query-performance ×1