索引本来就会降低插入和更新的速度,你只能具体分析你的SQL语句了.
 先做一个查询计划,有可能的话把复合索引拆分.

解决方案 »

  1.   

    例如
    正式表temp1有COL1,COL2,COL3,COL4,COL5,COL6,COL7,COL8 几个字段
    COL1,COL2,COL3,COL4,COL5为联合主键,COL6为待更新的字段,COL6,COL7,COL8 都有缺省值,正式表可能有四五十万条记录。临时表temp2 COL1,COL2,COL3,COL4,COL5,COL6 几个字段
    正常情况下临时表有几百条记录,特殊情况下可能有几万条记录。
    现在要把临时表的数据插入或更新到正式表中。
    现在的写法
    插入
    insert into temp1 (COL1,COL2,COL3,COL4,COL5,COL6) 
    select COL1,COL2,COL3,COL4,COL5,COL6 from temp2 a where not exists (select 1 from temp1 where COL1=a.COL1 and COL2=a.COL2 and COL3=a.COL3 and COL4=a.COL4 and COL5=a.COL5)
    更新
    update temp1 a set COL6=(select COL6 from temp2 where COL1=a.COL1 and COL2=a.COL2 and COL3=a.COL3 and COL4=a.COL4 and COL5=a.COL5) where exist (select 1 from temp2 where COL1=a.COL1 and COL2=a.COL2 and COL3=a.COL3 and COL4=a.COL4 and COL5=a.COL5)
    按这种写法程序得执行几个小时才能执行完。
    如何优化SQL语句,或者从数据结构上如何优化?
      

  2.   

    对于你的insert 语句,可以这么调试:
     1.看看  select 1 from temp1 where COL1=a.COL1 and COL2=a.COL2 and COL3=a.COL3 and COL4=a.COL4 and COL5=a.COL5) 花了多少时间,具体的查询计划. 2. 加上NOT exist 关键字后,再看看整个子查询花了多少时间 3. 使用DirectPath,先禁用目标表上的索引维护
         alter index ix_temp1(temp1表上的索引名称) unusable;
         alter session set skip_unusable_indexes=true;
         insert /*+ append */ into temp1 ... 4. 如果以上的方法还不能提高效率的话,建议装一个lecco sql expert
        for oracle,或许这个软件会给你一个优化的SQL方案.  
      

  3.   

    哪里能下载到lecco sql expert for oracle解密版