我有以下查询
UPDATE rec_analyst
SET analyst_name = (SELECT DISTINCT min (LIQA_ANALYST_LAST_NAME)
FROM LIQA
WHERE LIQA_ANALYST_ID = analyst_extern_id
AND LIQA_TS_INSERT = '15.09.2011'
)
WHERE analyst_provider_id = 4
解释计划显示大约4000的成本,但数据库负载是100%,甚至一小时后这个工作还没有准备好。 这里的解释计划输出:
------------------------------------------------------------------------------------
DESC |OBJECT NAME |COST| # |BYTES |
------------------------------------------------------------------------------------
UPDATE STATEMENT, GOAL =ALL_ROWS| | 34| 16572| 331440|
-------------------------------------------------------------------------------------
UPDATE |REC_ANALYST | | | |
-------------------------------------------------------------------------------------
TABLE ACCESS FULL |REC_ANALYST | 34| 16572|331440 |
-------------------------------------------------------------------------------------
SORT AGGREGATE | | | |24 |
-------------------------------------------------------------------------------------
TABLE ACCESS FULL |REC_LIQA_LOAD_INQUIRY_ANALYST |3965|1 |24 |
-------------------------------------------------------------------------------------
我该如何优化它?
答案 0 :(得分:5)
你可以尝试:
MERGE INTO rec_analyst ra
USING ( SELECT LIQA_ANALYST_ID analyst_id, MIN(LIQA_ANALYST_LAST_NAME) min_name
FROM LIQA
WHERE LIQA_TS_INSERT = '15.09.2011'
GROUP BY LIQA_ANALYST_ID
) liqa_extract
ON ( liqa_extract.analyst_id = ra.analyst_extern_id
AND ra.analyst_provider_id = 4
)
WHEN MATCHED THEN UPDATE SET ra.analyst_name = liqa_extract.min_name;
答案 1 :(得分:1)
询问您的DBA是否有可能/有利于在以下任何一个(最好是两个)上添加索引:
表:rec_analyst列:analyst_provider_id 表:LIQA列:LIQA_TS_INSERT
理想情况下,LIQA.analyst_id和rec_analyst.analyst_extern_id上有PK / FK索引,不知道您的架构认为很难说哪些索引会对整个系统有所帮助。