analyze table veh_info estimate statistics;
select count(id) from veh_info where id > 0;

解决方案 »

  1.   

    analyze table veh_info estimate statistics;这句话是什么意思,什么作用呢?
      

  2.   

    这个veh_info表每天还要插入将近20万的数据
    用这种分析合适吗?什么情况下可以用analyze ?
      

  3.   

    select count(*) from table
    用count(id)可能用到了index,看一下执行计划就清楚了
      

  4.   

    analyze table ... compute statics可能会有作用,试试
      

  5.   

    如果数据量变化比较大,建议还是一天做一次analyze table 这对count作用很明显
      

  6.   

    值得关注.
       我还没有遇到这样的情况.不过,我认为,主要的问题还是在于为什么你的
      consistent gets  65671
       physical reads   64678
    特别大. 
      我执行一个表格的查询
    SQL> select count(*) from tzjdjls;  COUNT(*)
    ----------
        241557
    Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=4 Card=1)
       1    0   SORT (AGGREGATE)
       2    1     INDEX (FAST FULL SCAN) OF 'IZJDJLS1' (NON-UNIQUE) (Cost=
              4 Card=436017)Statistics
    ----------------------------------------------------------
            870  recursive calls
              0  db block gets
           1329  consistent gets
           1048  physical reads
              0  redo size
            309  bytes sent via SQL*Net to client
            426  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              6  sorts (memory)
              0  sorts (disk)
              1  rows processed
      -----------------------------------
      大概一秒不到.  而物理扫描只花费了1048,你的数据就算是我的20倍,理论上20000左右差不多了.是什么导致物理扫描需要花费那么多.
       此外不知道,你的explain是否copy完全了,没有出现使用Index的信息.是没有拷贝了,还是说根本上没有启用. 如果没有使用那么是严重的问题.
       索引失效的原因,应该是系统觉得那么破烂的索引不如不用算了.所以,你的统计会便的慢.
       这样频繁插入的表,必须建立一个任务每天执行索引重建的过程.还有的就是上面提到的分析问题.
      

  7.   

    就是要建立一个job 每天运行
    create index in_veh_info_id on veh_info(id);是这个吗??
    为什么索引会失败呢???
      

  8.   

    我已经重建了索引  
    SQL> alter index pk_veh_info rebuild;索引已更改。已用时间:  00: 00: 41.09然后执行 select count(id) from veh_info;完整的执行计划SQL> select count(id) from veh_info; COUNT(ID)
    ----------
       4814067已用时间:  00: 00: 15.09Execution Plan
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   SORT (AGGREGATE)
       2    1     TABLE ACCESS (FULL) OF 'VEH_INFO'
    Statistics
    ----------------------------------------------------------
             14  recursive calls
              0  db block gets
          65674  consistent gets
          64675  physical reads
              0  redo size
            380  bytes sent via SQL*Net to client
            503  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    还是没用到索引,是什么原因呢??
      

  9.   

    我还发现了一个问题
    数据库里所有表进行count(id)的时候都不使用索引,比如SQL> select count(ID) from lk_info;COUNT(ID)
    -----------
             11已用时间:  00: 00: 00.01Execution Plan
    -------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   SORT (AGGREGATE)
       2    1     TABLE ACCESS (FULL) OF 'LK_INFO'Statistics
    -------------------------------------------------------
              0  recursive calls
              0  db block gets
              7  consistent gets
              5  physical reads
              0  redo size
            379  bytes sent via SQL*Net to client
            503  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed而在加入条件后就使用到了索引
    SQL> select * from veh_info where id='2002545125';
    已用时间:  00: 00: 00.01Execution Plan
    ---------------------------------
       0      SELECT STATEMENT Optimi
       1    0   TABLE ACCESS (BY INDE
       2    1     INDEX (UNIQUE SCAN)
    Statistics
    ---------------------------------
              0  recursive calls
              0  db block gets
              4  consistent gets
              2  physical reads
              0  redo size
           1439  bytes sent via SQL*N
            503  bytes received via S
              2  SQL*Net roundtrips t
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    这是什么原因??