Prior to MySQL 5.7.18, InnoDB processes SELECT COUNT(*) statements by scanning the clustered index. As of MySQL 5.7.18, InnoDB processes SELECT COUNT(*) statements by traversing the smallest available secondary index unless an index or optimizer hint directs the optimizer to use a different index. If a secondary index is not present, the clustered index is scanned.
创建一个辅助索引,建议用最小字段创建
mikulch
2021-07-16 17:09:36 +08:00
用你的表里面的,类型小,长度最少的列,创建一个二级索引。然后查询的时候使用 select count(column) from 'table' 来执行覆盖索引扫描,这样子的话就不用执行全表扫描了。