我正在尝试调整查询,我的解释计划中的所有内容都具有非常低的成本。我正在使用物化视图和适当的指数,但计划的最终成本是239,925,其他一切都在0-69之间。我错过了什么?我已经分区了大型mvs,并行性和索引。
对图片感到抱歉,但我不确定导出解释计划的其他方法。
代码如下所示:
UPDATE KC_TEST_REPORT_2 rep
SET ( department,
documenttype,
orgfunction,
risklevel,
assetcriticality,
cft
) = (
SELECT
dept.valstr Department,
doctype.valstr DocumentType,
orgFunc.valstr OrgFunction,
risk.valstr RiskLevel,
crit.valstr AssetCriticality,
cft.valstr CFT
FROM MV_LLATTRDATA_SHRUNK_V3 dept
left outer join MV_LLATTRDATA_SHRUNK_V3 doctype
ON doctype.defid = 3070055
AND doctype.attrid = 6
AND doctype.vernum = dept.vernum
AND doctype.defvern = dept.defvern
left outer join MV_LLATTRDATA_SHRUNK_V3 orgFunc
ON orgFunc.defid = 3070055
AND orgFunc.attrid = 2
AND orgFunc.vernum = dept.vernum
AND orgFunc.defvern = dept.defvern
left outer join MV_LLATTRDATA_SHRUNK_V3 risk
on risk.defid=3070055
and risk.attrid = 20
AND risk.vernum = dept.vernum
AND risk.defvern = dept.defvern
left outer join MV_LLATTRDATA_SHRUNK_V3 crit
ON crit.defid = 3070055
AND crit.attrid = 24
AND crit.vernum = dept.vernum
AND crit.defvern = dept.defvern
left outer join MV_LLATTRDATA_SHRUNK_V3 cft
ON cft.defid = 3070055
AND cft.attrid = 23
AND cft.vernum = dept.vernum
AND cft.defvern = dept.defvern
WHERE dept.id = rep.dataid
AND dept.defid = 3070055
AND dept.attrid = 4
AND doctype.id = rep.dataid
AND orgFunc.id = rep.dataid
AND orgFunc.entrynum = 1
AND risk.id = rep.dataid
AND crit.id = rep.dataid
AND cft.id = rep.dataid
AND dept.vernum = (SELECT MV.vernum
FROM MV_LLATTRBLOBDATA_VERNNUM_V1 MV
WHERE id = rep.dataid)
AND dept.defvern = (SELECT MV.MAX_DEFVERN
FROM MV_LLATTRDATA_MAX_VERSIONS_V1 MV
WHERE id = rep.dataid
AND defid = 3070055
AND attrid = 4));
答案 0 :(得分:1)
This is not the correct way to tune a query. The cost column is not a measurement of the cost of your query. It's used internally to compare between the many different plans the optimizer came up with to make its decision as to which one is best.
Instead, what you should be doing is looking at an execution plan, at the actual time for each step, the estimated rows vs. the actual rows, and maybe seeing if there are some missing indexes or something.
You might want to refer to the Database Performance Tuning Guide.