create unique index IND_MSCID on FACT_SALE (YEARMONTH, SHOPID, ANALYSE_ID, CATEID)update fact_sale a set (zyamt)=(select   zy from t_msc_amt b
       where a.shopid=b.shopid   and a.yearmonth=b.year_month and a.cateid=b.dl  and ANALYSE_ID='01' 
and b.zy_ly='自营')以上更新语句为什么总是全盘扫描,索引没用上. 请问要怎么建呢,t_msc_amt是临时表,尽量不在它上面建.

解决方案 »

  1.   

    a.shopid=b.shopid  and a.yearmonth=b.year_month and a.cateid=b.dl  and ANALYSE_ID='01' and b.zy_ly='自营'说明符合你这个条件的数据量很大。一般超过总数据量的10%以上,就会用全表扫描
      

  2.   

    建议楼主程序里面别用这样的update
    数据量大的时候,效率比较低, 还不如先关联出临时结果,然后再delete、insert
      

  3.   

    t_msc_amt临时表没有建立索引, 怎么能够使用呢? 临时表是需要建立索引的.
      

  4.   

    update t1 ... select ... from t2 ...
    一般是t1全盘扫描,t2引用索引
      

  5.   

    ORACLE是以cost based来做执行计划的,
    建了索引,查询时候不是100%用索引的
      

  6.   

    请参考:
    http://blog.csdn.net/pathuang68/archive/2009/04/16/4084116.aspx

    http://blog.csdn.net/pathuang68/archive/2009/04/16/4084139.aspx