例如..有一张表A,大概有上亿条数据
其中大概有20个字段,但是只有少数的字段上有索引..因为数据稽核的需要,每次都要执行 select count(*) from A ,每次执行都要1-2个小时
有什么办法可以优化吗?

解决方案 »

  1.   

    select count(主键) from A
    --or
    select count(1) from A
      

  2.   

    select count(*) from A
    看下执行计划走索引没?这种情况一般走索引的.
      

  3.   

    select /*parallel(t 8)*/ count(*) from tab;
    count(*)和count(1),count(主键)没有性能区别。
      

  4.   

    select /*+parallel(t1 8)*/ count(1) from yourtable t1;
      

  5.   

    select /*+parallel(t1 8)*/ count(1) from yourtable t1; 该语句在执行计划中花费时间要比 select count(1) from yourtable t1 中少测试了10000条数据, 2种写法 运行所花费的平均时间 差不多.. 
      

  6.   

    1w条记录差别不会太大,弄1kw级别试试,呵呵。