我有一个带子查询的oracle查询。子查询使用分析函数。如果将子查询更改为join,则执行时间会有明显改善。但在相同的其他类似查询中它仍然是相同的。在查看解释计划时,我能够发现显示出显着改进的子查询已更改为Oracle优化器自动加入。
当我搜索取消子查询的概念时,这基本上意味着将子查询转换为连接,它会在某些条件下提到,这种情况会发生。
https://blogs.oracle.com/optimizer/entry/optimizer_transformations_subquery_unesting_part_1
我不清楚的是解释计划,如何理解它多次执行
Query Synopsis:
JOIN CONTRACT CONTRACT
ON UWFILE.ID =CONTRACT.UWFILE_ID
AND CONTRACT.YEAR = UWFILE.YEAR
AND UWFILE.ORDER_NUM = CONTRACT.ORDER_NUM
AND CONTRACT.ID IN
(SELECT ID
FROM
(SELECT ID,
DENSE_RANK()over(partition BY CONTRACT.FACUL_NUM, CONTRACT.YEAR order by (CONTRACT.ENDOR_NUM) DESC) AS endor_rank
FROM CONTRACT
)
WHERE endor_rank = 1
)
Explain plan Synopsis:
Filter Predicates
AND CONTRACT.LAST_IN_FORCE=1
EXISTS (SELECT 0 FROM (SELECT ID ID,DENSE_RANK() OVER ( PARTITION BY CONTRACT.FACUL_NUM,CONTRACT.YEAR ORDER BY INTERNAL_FUNCTION(CONTRACT.ENDOR_NUM) DESC
VIEW
Filter Predicates
AND
ID=:B1
ENDOR_RANK=1
WINDOW Filter Predicates DENSE_RANK() OVER ( PARTITION BY CONTRACT.FACUL_NUM,CONTRACT.YEAR ORDER BY INTERNAL_FUNCTION(CONTRACT.ENDOR_NUM) DESC )<=1