即使没有要插入的记录,INSERT ALL语句也非常慢

时间:2017-09-14 11:28:33

标签: oracle oracle11g sql-insert oracle11gr2

这是11g。我有一个INSERT ALL语句,它使用SELECT来构建要插入的值。 select有一些子查询,用于检查记录是否已经存在。问题是插入时间超过30分钟,即使插入零行。 select语句本身就会立即运行,因此问题似乎是它与INSERT ALL一起使用时。我重写了使用MERGE的声明,但它同样糟糕。

该表没有触发器。主键索引和两个列上的唯一约束,但没有其他任何看起来可能导致问题。它目前有大约15000行,所以绝对不大。

是否有人建议可能导致此问题,或如何进行调试?

这是INSERT ALL语句。

    insert all
  into template_letter_merge_fields (merge_field_id, letter_type_id,table_name,field_name,pretty_name, tcl_proc)
            values (template_let_mrg_fld_sequence.nextval,letter_type_id,table_name,field_name, pretty_name, tcl_proc)
select lt.letter_type_id,
    i.object_type as table_name,
    i.interface_key as field_name,
    i.pretty_name as pretty_name,
    case 
    when w.widget = 'dynamic_select' then
        'dbi::'||i.interface_key||'::get_name'
    when w.widget = 'category_tree' and 
         i.interface_key not like '%_name' and 
         i.interface_key not like '%_desc' then
        'dbi::'||i.interface_key||'::get_name'
    else
        'dbi::'||i.interface_key||'::get_value'
    end as tcl_proc
  from template_letter_types lt,                          
     dbi_interfaces i 
     left outer join acs_attributes aa on (aa.object_type||'_'||aa.attribute_name = i.interface_key
                           and decode(aa.object_type,'person','party','aims_organisation','party',aa.object_type) = i.object_type)
     left outer join flexbase_attributes fa on fa.acs_attribute_id = aa.attribute_id
     left outer join flexbase_widgets w on w.widget_name = fa.widget_name
 where i.object_type IN (select linked_object_type
                     from template_letter_object_map lom
                    where lom.interface_object_type = lt.interface_object_type
                    union select lt.interface_object_type from dual
                    union select 'template_letter' from dual)  
   and lt.interface_object_type = lt.interface_object_type
   and not exists (select 1
                from template_letter_merge_fields m
              where m.sql_code is null
                 and m.field_name = i.interface_key
                 and m.letter_type_id = lt.letter_type_id)
   and not exists (select 1
                from template_letter_merge_fields m2
              where m2.pretty_name = i.pretty_name
                 and m2.letter_type_id = lt.letter_type_id)

0 个答案:

没有答案