select count(1) from FX_RETURNBOOKCHECKLIST fxreturnbo0_ where  fxreturnbo0_.BOOKID='164                             ' AND fxreturnbo0_.RETURNID='00025.S0000001' 
上面一个简单的SQL,执行时间2.6秒,去掉任意一条件后,如下:
select count(1) from FX_RETURNBOOKCHECKLIST fxreturnbo0_ where  fxreturnbo0_.BOOKID='164                             '
这个执行时间0.015秒。
注:上面的SQL语句是hibernate自动生成的。
再看看这样一个SQL,自己写的。查询结果与第一句SQL完全一样。但查询时间相关甚远。
select * from fx_returnbookchecklist where returnid='00025.S0000001' and bookid='164'
这个只需0.031秒。
请大家帮忙分析这是什么原因导致的??是不是hibernate?

解决方案 »

  1.   

    returnbookchecklist 表有多少记录?
    满足条件returnid='00025.S0000001' and bookid='164'有多少记录?
      

  2.   

    returnbookchecklist有数据70多万,满足条件returnid='00025.S0000001' and bookid='164'有1条记录,这个问题已解决,空格造成,但是新的一个问题又出来了。
    select b.returnid
    from fx_returnbookchecklist b
    where b.returnid='00025.S0000001' 
    这样一个SQL查询速度0.047秒,
    select b.scale
    from fx_returnbookchecklist b
    where b.returnid='00025.S0000001' 
    现在只是查了相同表中另一个字段scale执行时间2.578秒,本以为是索引的原因,又做了一个测试取满足条件行的主键值
    select b.id
    from fx_returnbookchecklist b
    where b.returnid='00025.S0000001' 
    同样执行了2.641秒。只有一个字段它的查询速读很快。其他都很慢。
    select b.scale,b.netamount,b.discount,b.amount,b.returnid
    from fx_returnbookchecklist b
    where b.returnid='00025.S0000001' 
    同样执行速度相当慢2.578秒。大家帮忙分析一下是么问题
      

  3.   

    select b.returnid 
    from fx_returnbookchecklist b 
    where b.returnid='00025.S0000001' 
    这句肯定快过其他的.你能贴出以下几句sql的执行计划吗?
    select b.returnid 
    from fx_returnbookchecklist b 
    where b.returnid='00025.S0000001'; 
    select b.scale 
    from fx_returnbookchecklist b 
    where b.returnid='00025.S0000001';
    猜第二句会多一部分在TABLE ACCESS BY INDEX ROWID.