数据库:oralce9i 
查询语句:select * from System_Log a where  
a.log_Date >= to_date('2010-07-01 00:00:00','yyyy-mm-dd hh24:mi:ss') 
and a.log_Date <= to_date('2010-07-29 09:37:00','yyyy-mm-dd hh24:mi:ss') 
and a.member_Code='00000000'  order by a.log_Date asc 数据库中建了2个用户test1,test2,2个用户的表结构完全一致。System_Log的记录分别为19w,13w. 
查询速度test1:30秒,test2:1s,为什么? 

解决方案 »

  1.   

    开始菜单-->运行-->cmdsqlplus / as sysdba;set autotrace on
    set timing on你要执行的sql,贴出执行任务,让大家帮你看看。
      

  2.   

    在cmd中,ERROR:
    ORA-12560: TNS: 协议适配器错误
      

  3.   

    34974 rows selectedExecuted in 353.469 seconds
      

  4.   

    sqlplus / as sysdba;
    这个改成
    sqlplus 用户名@sid/密码 as sysdba
      

  5.   

    索引建的是一样的,set autotrace on的时候出现Cannot SET AUTOTRACE
      

  6.   

    SQL> select count(*) from System_Log a where
      2  a.log_Date >= to_date('2010-07-01 00:00:00','yyyy-mm-dd hh24:mi:ss')
      3  and a.log_Date <= to_date('2010-07-29 09:37:00','yyyy-mm-dd hh24:mi:ss')
      4  and a.member_Code='00000000' order by a.log_Date asc;  COUNT(*)
    ----------
         34974
    test1
    已用时间:  00: 00: 14.73执行计划
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE
       1    0   SORT (AGGREGATE)
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'SYSTEM_LOG'
       3    2       INDEX (RANGE SCAN) OF 'IX_SYSTEM_LOG_1' (NON-UNIQUE)
    统计信息
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
          23471  consistent gets
          11025  physical reads
              0  redo size
            378  bytes sent via SQL*Net to client
            372  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedtest2
    已用时间:  00: 00: 00.68执行计划
    ----------------------------------------------------------
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=357 Card=1 Bytes=17)
       1    0   SORT (AGGREGATE)
       2    1     TABLE ACCESS (FULL) OF 'SYSTEM_LOG' (Cost=357 Card=1 Byt
              es=17)统计信息
    ----------------------------------------------------------
              0  recursive calls
              0  db block gets
           4949  consistent gets
           4917  physical reads
              0  redo size
            378  bytes sent via SQL*Net to client
            372  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
      

  7.   

    加个索引确实能解决问题,问题是为什么会出现这个情况
    分析索引
    analyze index t_idx validate structure;
    select name,lf_rows from index_stats;
    A如下
    NAME LF_ROWS
    ------------------------------ ----------
    IX_SYSTEM_LOG_1 184299
    select count(*) from system_log;
      COUNT(*)
    ----------
      184242
    B如下
    NAME LF_ROWS
    ------------------------------ ----------
    IX_SYSTEM_LOG_1 140882
    select count(*) from system_log;
      COUNT(*)
    ----------
      140882
      

  8.   

    问题转到http://topic.csdn.net/u/20100729/15/1ed438ca-9b0d-4e56-a94a-6a4a07b6155a.html?seed=338565391&r=67334238