Sql 需要查询优化
我有以下疑问:Sql 需要查询优化,sql,oracle,query-optimization,Sql,Oracle,Query Optimization,我有以下疑问: 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.o
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行,explain plan中的成本是2990
我怎样才能用“不存在”代替“存在”
和磁盘状态_类型不在(1,7)
是否有优化查询的建议?优化查询的建议:
和disc.status\u type NOT IN(1,7)
作为where子句中的第一个条件我不确定not EXISTS是否是正确的选择。您的访问路径似乎是disc.source\u code或oeh.order\u number,以更具选择性的为准。希望其中一个被索引。你也可以在组织id上添加索引,如果它比标题id更有选择性。正如@StanislavL所说,你可以删除disc.status\u type NOT IN(1,7)。disc.status\u type NOT IN(1,7)不是无效的吗?下一个条件假设类型为3,4,6或类型=12@StanislavL这些是要求:其中disc.status_type不在(1,7)-未取消和未发布)和((disc.status_type在(3,4,6))或(disc.date_completed>TRUNC(SYSDATE)-400和disc.status_type=12-关闭))我在APPS.wip\u discrete\u jobs.status\u type上有两个索引,如果一列上有两个索引会有什么影响?如果两个索引都只在一列上,您可以删除其中一个。否则,Oracle将根据您的查询选择更好的。