[英]Performance tuning query
我必须执行 Tune a Query。 我的查询是一个动态的查询
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%。
在 store_1 中,尝试通过使用具有主键、唯一键的列创建第一个条件来重写 where 子句,然后是其他条件。
在 tab_1 上为 (subclass_id, category_id) 创建索引
在 tab_1 上为 item_number 创建索引。
重新运行并再次检查性能。
注意:创建索引可能需要一段时间,所以请耐心等待。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.