我有个SQL
select 1 from a where.....这样执行计划是INDEX FAST FULL SCAN,如果改成
select A from a where ....执行计划就变成TABLE ACCESS FULL,这是什么意思。要怎么避免这种的全表扫描。。

解决方案 »

  1.   

    你的where子句怎么写的?索引是怎么建的?
      

  2.   

    猜一下:
    因为select 1 from a where  中,得到的结果只是个常量1,那么只要返回的行数等于满足 where 条件的行数即可,此时,where 后面的条件可以使用 到某个索引.
    当 语句为 select A from a where  时,因为返回的结果是A字段的值,但是此时A 字段并不被前面那个索引所包含,而且可能表比较小,或者返回的值集相对较多,全表扫描倒相对快一下,因此走了全表扫描.在A字段上建立了索引,此时可能有这么三种访问路径了,一是 访问前面那个索引,二是全表扫描,三是访问A 字段上的新索引.  因为可能where 后面没有A 字段的条件,或者条件不合适,索引还是全表扫描来的快一些. 可以尝试将字段A包含进前面使用的索引,那样的话,第二条语句很可能还是走的前面那个索引.
    请楼主试试看吧.
      

  3.   

    SQL语句
    Select e.fexp_rate as fexp_rate
      from fexpense       e,
           fconsign       c,
           csubchargeitem s,
           ccustsuppview  csv,
           cuser          cu1,
           cuser          cu2
     where (e.fexp_creator = :1 or e.FEXP_CONSIGN_ID IN
           (SELECT FCSG_CONSIGN_ID
               FROM FCONSIGN
              WHERE FCSG_CREATOR = :"SYS_B_04"))
       and e.fexp_consign_id = c.fcsg_consign_id(+)
       and e.fexp_charge_id = s.csci_ci_id(+)
       and e.fexp_settlerment_object = csv.accountNumber(+)
       and c.fcsg_creator = cu1.cusr_user_id(+)
       and c.fcsg_canvasser = cu2.cusr_user_id(+)
       and e.fexp_forward_flag != :"SYS_B_05"
       and e.fexp_cancel_flag != :"SYS_B_06"
       and e.fexp_lump_flag != :"SYS_B_07"
       and (e.fexp_consign_audit_flag = :"SYS_B_08" or e.fexp_lock_flag = :"SYS_B_09")
       and (:"SYS_B_10" <> :"SYS_B_11" or e.fexp_rp_flag = :"SYS_B_12")
       and ((:"SYS_B_13" = :"SYS_B_14" and :"SYS_B_15" = :"SYS_B_16") 
       and (:"SYS_B_17" = :"SYS_B_18" and :"SYS_B_19" = :"SYS_B_20"))
       and (:"SYS_B_21" = :"SYS_B_22" and :"SYS_B_23" = :"SYS_B_24")
       and (:"SYS_B_25" = :"SYS_B_26" and :"SYS_B_27" = :"SYS_B_28")
       and e.fexp_org_id = :2
     order by e.fexp_settlerment_object ASC, e.fexp_currency_code ASC索引
    create index IDX_FEXP2 on FEXPENSE (fexp_consign_id,fexp_charge_id,fexp_settlerment_object,fexp_org_id,fexp_consign_audit_flag,fexp_lock_flag,fexp_forward_flag,fexp_cancel_flag,fexp_lump_flag,fexp_creator,fexp_rp_flag,fexp_currency_code)
      tablespace HYFFINDEX
      pctfree 10
      initrans 2
      maxtrans 255
      storage
      (
        initial 64K
        minextents 1
        maxextents unlimited
      );
      

  4.   

    把字段fexp_rate建立到联合索引后是可以避免全表扫描,不过我select的项目很多,这样建是不太可能的。而且我觉得奇怪的是为什么SELECT项目会影响到全表扫描
      

  5.   

    我有个SQL
    select 1 from a where.....这样执行计划是INDEX FAST FULL SCAN,如果改成
    select A from a where ....执行计划就变成TABLE ACCESS FULL,这是什么意思。要怎么避免这种的全表扫描。。
    ----------------------------------------------------
    把列A也加到索引中.
      

  6.   

    用hint了.........指定索引不就行了?俺是oracle初学者..
      

  7.   

    to bugchen888(臭虫) :这样是可以的,不过我的select项目有很多,不可能都写进去啊
      

  8.   

    tandy_cs_201() ( ) 信誉:99    Blog   加为好友  2007-05-23 16:28:31  得分: 0  
     
     
       to bugchen888(臭虫) :这样是可以的,不过我的select项目有很多,不可能都写进去啊
      
     
    ----------------------------------------
    那退而求其次,把where子句中的所有字段加到索引中.然后
    analyze index xxx validate structure;
      

  9.   

    analyze index xxx validate structure;
    -------是什么意思
    按bugchen888(臭虫)的执行了,还是不行
      

  10.   

    cbo 需要经常分析表,建议hint一吧