对于count来说统计数据话,没有什么好的方法。具体还要看应用
统计是实时还是非实时的,从处理方法来说是不一样的。
如果是实时的话消耗硬件资源是非常大的,如果是非实时统计的
存入临时表去取数据这样既能调查询效率,对机器资源的消耗也小,
只不过定时去update就可以了。

解决方案 »

  1.   

    即使createtime和createman是联合索引的话,从执行计划来看也不
    不会太高。楼主可以模拟一下两千万条数据下执行效率。
      

  2.   

    看执行计划了么,看看有没有用上索引
    count(*)或者count(createman)这样应该都比
    count(createTime)好
      

  3.   

    SQL> explain plan for select count(*) from customer;ExplainedSQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    Plan hash value: 2982274804
    ------------------------------------------------------------------------------
    | Id  | Operation             | Name         | Rows  | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT      |              |     1 | 10724   (2)| 00:02:09 |
    |   1 |  SORT AGGREGATE       |              |     1 |            |          |
    |   2 |   INDEX FAST FULL SCAN| SYS_C0011627 |    20M| 10724   (2)| 00:02:09 |
    ------------------------------------------------------------------------------SQL> explain plan for select count(1) from customer;ExplainedSQL> select * from table(dbms_display);select * from table(dbms_display)ORA-00904: "DBMS_DISPLAY": 标识符无效SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    Plan hash value: 2982274804
    ------------------------------------------------------------------------------
    | Id  | Operation             | Name         | Rows  | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT      |              |     1 | 10724   (2)| 00:02:09 |
    |   1 |  SORT AGGREGATE       |              |     1 |            |          |
    |   2 |   INDEX FAST FULL SCAN| SYS_C0011627 |    20M| 10724   (2)| 00:02:09 |
    ------------------------------------------------------------------------------9 rows selectedSQL> explain plan for select count(1) from customer;ExplainedSQL> select * from table(dbms_display);select * from table(dbms_display)ORA-00904: "DBMS_DISPLAY": 标识符无效SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    Plan hash value: 2982274804
    ------------------------------------------------------------------------------
    | Id  | Operation             | Name         | Rows  | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT      |              |     1 | 10724   (2)| 00:02:09 |
    |   1 |  SORT AGGREGATE       |              |     1 |            |          |
    |   2 |   INDEX FAST FULL SCAN| SYS_C0011627 |    20M| 10724   (2)| 00:02:09 |
    ------------------------------------------------------------------------------9 rows selected
    为什么count(*) 、ount(createman)和count(createTime)的执行计划是一样的
      

  4.   

    执行计划一样是正常的,因为你有索引
    要提高count速度,似乎没什么好办法,
    可以尝试开并行看看,
      

  5.   

    alter table customer parallel 4
    select /*+parallel(customer 4)*/ count(*) from customer不行还是很慢啊 
      

  6.   

    createman  createTime组合index
      

  7.   

    createman是非空字段吧。
    还是count(createman)快,因为他只要找index,不用访问表既可以完成工作
      

  8.   

    createman是非空字段吧。
    还是count(createman)快,因为他只要找index,不用访问表既可以完成工作
      

  9.   

    注意一下,如果索引列中含有 NULL,COUNT计算会有偏差
     
      

  10.   


    count 会让索引走IFFS 一样的,甚至更差
      

  11.   

    如果表有适合建立位图索引的列(Customer表的话应该有性别列),那么建立位图索引,然后再用count(位图索引的列),那么效率非常非常快!不超过1秒!
      

  12.   

    先要搞懂index,createTime和createman是否可以为空???