mysql count在myisam引擎下很快,但仅限于查询表的”所有行”比较快, 因为Myisam对行数进行了存储.一旦有条件的查询, 速度就不再快了.尤其是where条件的列上没有索引.
如:
在一个百万级千万级的数据库下,计算大于一百的总行说 select count(*) from lx_com where id>=100; (1000多万行用了6.X秒)
此时 select count(*) from lx_com; 比较快 select count(*) from lx_com where id<100; 也是比较快的 是否可以 这两个值做计算
select count(*) frol lx_com -select count(*) from lx_com whereid<100; 这个是比单独查找>=100条的数据要快的多 ,
综上获得 >=100条的数据
select (select count(*) from lx_com) - (select count(*) from lx_comwhere id<100) as con