我有以下查询:
select oeh.header_id, oeh.order_number, oeh.ordered_date,oeh.sold_to_org_id as customer_id ,arc.customer_name as customer_name, oeh.INVOICE_TO_ORG_ID
, oel.attribute1 attribute1, oel.attribute6 attribute6, oel.line_id, oel.line_number, oel.ordered_quantity, disc.wip_entity_id, disc.date_closed, disc.date_released, disc.date_released, disc.date_completed
from (APPS.oe_order_headers_all oeh INNER JOIN APPS.oe_order_lines_all oel
ON oeh.org_id = oel.org_id -- not indexed
and oeh.header_id = oel.header_id) -- both indexed
INNER JOIN APPS.ar_customers arc
ON arc.customer_id = oeh.sold_to_org_id -- both indexed
INNER JOIN XXCUS.xxgex_assemblies asm
ON oel.line_id = asm.line_id -- BOTH INDEXED
INNER JOIN APPS.wip_discrete_jobs disc
ON disc.primary_item_id = asm.inventory_item_id -- both indexed
where oel.link_to_line_id is null -- indexed
and oeh.ordered_date > '31-DEC-2013'
and disc.status_type NOT IN (1,7) -- Not Cancelled and Unreleased )
and (
( disc.status_type in (3,4,6) )
or
( disc.date_completed > TRUNC(SYSDATE) - 400
and disc.status_type = 12 -- CLOSED
)
)
and disc.source_line_id is not null
and disc.source_code = 'WICDOL'
and oeh.order_number between 1400000 and 1420050;
where子句中的列主要是索引,我的查询返回7行,解释计划中的成本是2990.
我如何使用NOT EXIST而不是
和disc.status_type NOT IN(1,7)
有任何优化建议吗?
答案 0 :(得分:2)
优化查询的建议:
and disc.status_type NOT IN (1,7)
移动为where子句中的第一个条件。我不确定NOT EXISTS在这里是不是正确的选择。
答案 1 :(得分:1)
似乎您的访问路径是disc.source_code或oeh.order_number,无论哪个更具选择性。希望他们中的一个被索引。如果它比header_id更具选择性,你也可以在org_id上添加索引。正如@StanislavL所说,你可以删除disc.status_type NOT IN(1,7)。