Oracle SQL优化:分层查询
我有一个查询,它获取记录列表并跟踪每个记录的谱系,但它会永远运行。谁能帮助我提高性能?
WITH root_nodes AS
(SELECT distinct dlot.dim_lot_key AS lot_key, facility, lot
FROM pedwroot.dim_lot dlot
JOIN AT_LOT a
ON (a.at_lot = dlot.lot AND a.at_facility = dlot.facility)
WHERE (dlot.has_test_lpt = 'Y'
or dlot.has_post_test_lpt = 'Y') and a.at_facility = 'MLA'),
upstream_genealogy AS
(SELECT /*+ INDEX(fact_link_lot IX_R_FLLOT_DLOT_2)*/DISTINCT CONNECT_BY_ROOT
fllot.dst_lot_key AS root_lot_key,
fllot.src_lot_key
FROM pedwroot.fact_link_lot fllot
CONNECT BY NOCYCLE PRIOR fllot.src_lot_key = fllot.dst_lot_key
START WITH fllot.dst_lot_key IN (SELECT lot_key FROM root_nodes)),
at_lst AS
(Select *
FROM pedwroot.dim_lot dlot_lst
JOIN upstream_genealogy upgen
ON (upgen.src_lot_key = dlot_lst.dim_lot_key)
where dlot_lst.has_assembly_lpt = 'Y')
SELECT distinct dlot_root.lot AS AT_LOT,
dlot_root.facility AS AT_FACILITY,
dfac_root.common_name AS AT_SITE,
dlot_root.LTC AS AT_LTC,
al.lot AS AT_LST,
dlot_src.lot AS FAB_LOT,
dlot_src.facility AS FAB_FACILITY,
dfac_src.common_name AS FAB_SITE
FROM upstream_genealogy upgen
JOIN at_lst al
ON (upgen.root_lot_key = al.root_lot_key)
JOIN pedwroot.dim_lot dlot_src
ON (upgen.src_lot_key = dlot_src.dim_lot_key)
JOIN pedwroot.dim_lot dlot_root
ON (upgen.root_lot_key = dlot_root.dim_lot_key)
JOIN pedwroot.fact_lot flot
ON (dlot_root.dim_lot_key = flot.lot_key)
JOIN pedwroot.dim_facility dfac_root
ON (flot.facility_key = dfac_root.dim_facility_key)
JOIN pedwroot.dim_facility dfac_src
ON (flot.fab_facility_key = dfac_src.dim_facility_key)
WHERE dlot_src.has_fab_lpt = 'Y';
以下是该查询的解释计划
I have this query that get list of records and traces the genealogy of each record but it runs forever. Can anyone help me improve the performance?
WITH root_nodes AS
(SELECT distinct dlot.dim_lot_key AS lot_key, facility, lot
FROM pedwroot.dim_lot dlot
JOIN AT_LOT a
ON (a.at_lot = dlot.lot AND a.at_facility = dlot.facility)
WHERE (dlot.has_test_lpt = 'Y'
or dlot.has_post_test_lpt = 'Y') and a.at_facility = 'MLA'),
upstream_genealogy AS
(SELECT /*+ INDEX(fact_link_lot IX_R_FLLOT_DLOT_2)*/DISTINCT CONNECT_BY_ROOT
fllot.dst_lot_key AS root_lot_key,
fllot.src_lot_key
FROM pedwroot.fact_link_lot fllot
CONNECT BY NOCYCLE PRIOR fllot.src_lot_key = fllot.dst_lot_key
START WITH fllot.dst_lot_key IN (SELECT lot_key FROM root_nodes)),
at_lst AS
(Select *
FROM pedwroot.dim_lot dlot_lst
JOIN upstream_genealogy upgen
ON (upgen.src_lot_key = dlot_lst.dim_lot_key)
where dlot_lst.has_assembly_lpt = 'Y')
SELECT distinct dlot_root.lot AS AT_LOT,
dlot_root.facility AS AT_FACILITY,
dfac_root.common_name AS AT_SITE,
dlot_root.LTC AS AT_LTC,
al.lot AS AT_LST,
dlot_src.lot AS FAB_LOT,
dlot_src.facility AS FAB_FACILITY,
dfac_src.common_name AS FAB_SITE
FROM upstream_genealogy upgen
JOIN at_lst al
ON (upgen.root_lot_key = al.root_lot_key)
JOIN pedwroot.dim_lot dlot_src
ON (upgen.src_lot_key = dlot_src.dim_lot_key)
JOIN pedwroot.dim_lot dlot_root
ON (upgen.root_lot_key = dlot_root.dim_lot_key)
JOIN pedwroot.fact_lot flot
ON (dlot_root.dim_lot_key = flot.lot_key)
JOIN pedwroot.dim_facility dfac_root
ON (flot.facility_key = dfac_root.dim_facility_key)
JOIN pedwroot.dim_facility dfac_src
ON (flot.fab_facility_key = dfac_src.dim_facility_key)
WHERE dlot_src.has_fab_lpt = 'Y';
Below is the explain plan of this query
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基数突然从 1100 万变为 1 看起来像是一个问题。从查询中删除表和谓词,直到准确找出导致估计值不佳的原因。
大多数情况下,这些问题是由错误的统计数据引起的,请尝试收集所有相关表的统计数据。 (我可以想到许多其他潜在问题,但在您可以稍微缩小问题之前,可能不值得猜测。)
The sudden change in cardinality from 11 million to 1 looks like a problem. Remove tables and predicates from the query until you find out exactly what is causing that poor estimate.
Most of the time these issue are caused by bad statistics, try gathering stats for all the related tables. (I can think of dozens of other potential problems, but it's probably not worth guessing until you can shrink the problem a little.)