有 100 条数据 那么用  select  Count(*) from  table 查出总数量 还是 算快的
如果 有 5000000 条数据  select  Count(*) from  table 就很慢了 ;; 请问有没有 办法使它 执行更快!!  谢谢了  

解决方案 »

  1.   

    本以为select count(1) from table 会快点,结果是慢了... 
    我的是400多万,查出来还不到1秒, 这个速度应该还可以接受吧,如果楼主想继续提高,可以提高硬件...SQL> set timing on
    SQL> select count(*) from customer;  COUNT(*)
    ----------
       4343867已用时间:  00: 00: 00.64
    SQL> select count(1) from customer;  COUNT(1)
    ----------
       4343871已用时间:  00: 00: 00.79
    SQL> 
      

  2.   

    索引很重要,建好了索引 类似的count操作应该很快的~
      

  3.   

    那你试试select  Count(rid) from  table 
    的性能如何
      

  4.   

    参考一下这个帖以前vc555大侠详细介绍过一次的
    http://topic.csdn.net/u/20090617/16/401ea743-48fa-4449-ab85-6e955fea1a01.html
      

  5.   

    select count(*) from table
    是不走索引的。因为在null值上不存在索引!
    如果你想我加快select count(*) from table 的速度,只有利用Oracle的并行执行!
    select /* +parallel(table,5)*/count(*) from table
    这个是以消耗cpu资源为代价的,如果cup占用率高,那就别用。
    表中数据越多,速度越明显!!!!
      

  6.   

    没有条件,建索引也不会走呀
    select count(主键字段) from tablename
      

  7.   

    SELECT COUNT(ROWID) FROM TABLE, try
      

  8.   

    可以建立索引,简单的方法就是 select count(列名) from Table
                              这样也是比较有效的,我感觉在操作数据库时无论什么语句最好别用*  
      

  9.   

    \
    mysql> select count(*) from mytable;
    +----------+
    | count(*) |
    +----------+
    |   973442 |
    +----------+
    1 row in set (2.84 sec)mysql> select count(name) from mytable;
    +-------------+
    | count(name) |
    +-------------+
    |      973442 |
    +-------------+
    1 row in set (3.33 sec)那 这 是 怎么回事 啊 !! 不是说 * 是 很慢的么 
      

  10.   

    我感觉在操作数据库时无论什么语句最好别用*
    =============================================
    country(*) 和 count(name) 结果是不一样的。
      

  11.   

    看上面的好像count(*)比count(1)是间要快啊,为什么啊?
      

  12.   

     对啊  我也 不知道 为什么呢 ?? count(name ) 是我 建的 索引 列 等待 高手!!!
      

  13.   

    select  Count(*) from  table
    这个语句建个索引能提高性能吗?
      

  14.   

    select count(rowid) for table还有如果建立索引但没有条件只是count(索引)有效果吗
      

  15.   

    试过了,time :count(rowid)< count(*) <count(1)
      

  16.   

    time :count(关键字)<count(rowid) < count(*) <count(1)