在表中数据非常多的时候,如下count语句可能需要数秒时间
select count * from t_goods where xxx
我们可以通过限制count最大数量以提高查询速度,将查询速度控制在毫秒级,sql如下
select count(*) from(
select 1 from t_goods where xxx limit 1000
) temp
这种方式适用于对很大的总数不关心的情况,比如淘宝商品搜索结果(只展示前50页)等。
在表中数据非常多的时候,如下count语句可能需要数秒时间
select count * from t_goods where xxx
我们可以通过限制count最大数量以提高查询速度,将查询速度控制在毫秒级,sql如下
select count(*) from(
select 1 from t_goods where xxx limit 1000
) temp
这种方式适用于对很大的总数不关心的情况,比如淘宝商品搜索结果(只展示前50页)等。