count()优化小技巧

count() 优化

误区:

1:myisamcount()非常快

: 是比较快,.但仅限于查询表的所有行比较快, 因为Myisam对行数进行了存储.

一旦有条件的查询, 速度就不再快了.尤其是where条件的列上没有索引.

 

2: 假如,id<100的商家都是我们内部测试的,我们想查查真实的商家有多少?

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 where id<100;

select (select count(*) from lx_com) - (select count(*) from lx_com where id<100)


猜你喜欢

转载自blog.51cto.com/5660061/2376120