SELECT count(1) as count FROM table WHERE update_time >= '1628651608' AND update_time <= '1629256408'  AND  `online` = '1';


这段MYSQL查询要38s,该怎么优化呢?

添加online和update_time 联合索引

 

性能对比结论

count(可空字段) < count(非空字段) = count(主键 id) < count(1) ≈ count(*)