我有一个奇怪的问题,我没有找到解决方案。我有以下查询,执行时间超过5分钟。查询性能非常慢,即使我有很少的记录将被插入。如果我删除insert语句并仅运行select query语句,则查询将在2到5秒内执行。这有什么问题?在这种情况下,如何提高插入查询性能?
INSERT INTO TEMP_SERVICE_OPTION_EXTRACTION(ID,ICC,ASSIGNED_ANUMBER_ID,SERVICE_ID,PRODUCT_OPTION_ID,STATUS_ID,END_DATE,ORDER_NUMBER)
Select DISTINCT(SO.ID),SIM.ICC,SIM.ASSIGNED_ANUMBER_ID,SO.SERVICE_ID,SO.PRODUCT_OPTION_ID,SO.STATUS_ID,SO.END_DATE,DCR.SHOP_ORDER_NUMBER FROM
SIMCARD@FONIC_RETAIL SIM
JOIN SERVICE_OPTION@FONIC_RETAIL SO ON SO.SERVICE_ID=SIM.ASSIGNED_TO_SERVICE_ID
JOIN DANGAARD_CONFIRM_RECORD@FONIC_RETAIL DCR ON DCR.ICC = SIM.ICC
where SO.STATUS_ID IN (20,40)
and SO.ID < to_char(SYSDATE - numtodsinterval ( 1,'MINUTE' ), 'YYYYMMDDHH24MISS')||'0000'
and SO.ID > to_char(SYSDATE - numtodsinterval ( 1, 'HOUR' ), 'YYYYMMDDHH24MISS')||'0000'
答案 0 :(得分:1)
在这种情况下使用带有for循环的匿名PL / SQL块(每个步骤中只插入一行):
begin
for r in (
Select DISTINCT (SO.ID),SIM.ICC,SIM.ASSIGNED_ANUMBER_ID,SO.SERVICE_ID,SO.PRODUCT_OPTION_ID,SO.STATUS_ID,SO.END_DATE,DCR.SHOP_ORDER_NUMBER
FROM SIMCARD@FONIC_RETAIL SIM
JOIN SERVICE_OPTION@FONIC_RETAIL SO ON SO.SERVICE_ID=SIM.ASSIGNED_TO_SERVICE_ID
JOIN DANGAARD_CONFIRM_RECORD@FONIC_RETAIL DCR ON DCR.ICC = SIM.ICC
where SO.STATUS_ID IN (20,40)
and SO.ID < to_char(SYSDATE - numtodsinterval ( 1,'MINUTE' ), 'YYYYMMDDHH24MISS')||'0000'
and SO.ID > to_char(SYSDATE - numtodsinterval ( 1, 'HOUR' ), 'YYYYMMDDHH24MISS')||'0000'
) loop
INSERT INTO TEMP_SERVICE_OPTION_EXTRACTION(ID,ICC,ASSIGNED_ANUMBER_ID,SERVICE_ID,PRODUCT_OPTION_ID,STATUS_ID,END_DATE,ORDER_NUMBER)
VALUES (r.ID,r.ICC,r.ASSIGNED_ANUMBER_ID,r.SERVICE_ID,r.PRODUCT_OPTION_ID,r.STATUS_ID,r.END_DATE,r.SHOP_ORDER_NUMBER);
COMMIT;
end loop;
end;
如果这没有帮助,您必须ALTER TABLE TEMP_SERVICE_OPTION_EXTRACTION SHRINK SPACE
(如Slow query execution in an empty table. (after deleting a large amount of inserts)中所述)。
答案 1 :(得分:0)
由于您正在为所有表使用DB链接,因此您必须检查实现连接的方式(EXEC PLAN)。它可能会加入&#34;你的&#34;侧面或远程&#34;侧。尝试使用这些连接在远程端创建视图。如果加入您,Oracle必须提取所有&#34;所有表中的行,将它们放入TEMP中,然后执行查询。
PS:Oracle文档还解释了条件下,分布式查询可能会使用远程端的索引。
使用Google并搜索&#34; db link&#34;和&#34;分布式查询性能&#34;