我必须演出调整查询。我的查询是动态的,并且在下面
store_1:='select item_number from Tab_1
where subclass_id= ' || part_class_id || '
and category_id= '|| part_type_id || '
and delete_flag=0
and text11 != ''' || i.eccn_old ||'''' ;
open cursor for store_1;
loop
fetch cursor into record;
exit when record%notfound;
select count(1) into variable from Tab_1 a, Tab_2 b
where a.id=b.id
and a.item_number=record
and some condition;
if (variable>0) then
insert into table tab_3 values(record);
commit;
end if;
end loop;
The time taken by above code in approx 1 min for 150 Cursor records.
表Tab_1(1495093)行和Tab_2(6580252)行的大小很大。
此外,store_1的输出将超过100行,但又取决于条件 但在极少数情况下会超过5000。
我尝试通过创建全局临时表来调整整个过程" tab_4"并加入" tab_2"表并直接插入我的" Tab_3"表
Note tab_4 has only one column "item_number"
我的尝试低于
store_1:='insert into tab_4 select item_number from tab_1
where subclass_id= ' || part_class_id || '
and category_id= ' || part_type_id || '
and delete_flag=0 and text11 != ''' || i.eccn_old ||'''' ;
execute immediate store_1;
commit;
insert into tab_3 select b.item_number from tab_1 a, tab_4 b
where a.item_number=b.item_number
and b.release_date> somedate
and b.delete_flag=0
and (b.release_type =974 or b.release_type =975);
我认为联合表可以解决问题但不幸的是我的过程甚至需要更多的时间
The time taken was approx 3 min for 150 Cursor Records
请指导我调整代码,以便我的大致时间至少减少50-60%。
答案 0 :(得分:0)
尝试通过使用具有主键,唯一键,然后是其他条件的列创建第一个条件来重写where子句。
在tab_1上为(subclass_id,category_id)创建索引
在tab_1上为item_number创建索引。
重新运行并再次检查性能。
注意:创建索引可能需要一段时间,所以请耐心等待。