select count(id) from tb1

解决方案 »

  1.   

    select count(*) from tb1=====>select count(1) from tb1
      

  2.   

    用了select count(id) from tb1或select count(1) from tb1都不会改成聚集索引进行优化,仍然用普通索引
      

  3.   

    select count(1) from tb1
      

  4.   

    select count(1) from tb1
    正解
      

  5.   

    select count(*) from tb1 where id>0
      

  6.   

    select count(id) 
    from tb1
      

  7.   

    select count(1) from tb1
      

  8.   

    http://www.blog.com.cn/user25/lijunyi/archives/2005/213533.shtml
      

  9.   

    select count(1) from tb1,select count(id) from tb1,select count(*) from tb1
    的执行效率是一样的。
      

  10.   

    如果你的count(1) 使用了聚集索引,反而是最慢的。你需要选择全部数据,此时必须遍历,如果遍历聚集索引,实际上是对实际的数据页进行扫描。这反而是最差的。你可以建一个聚集索引,那一个非聚集索引,比较一下会使用什么索引?
    -------------------
    http://chinadba.cn
    最具实战经验的数据库优化,管理,设计,培训网
    目前更新了二篇文档