【问题标题】:Not able to optimize a SQL Query. Taking huge cost. Oracle Apps无法优化 SQL 查询。付出巨大的代价。甲骨文应用
【发布时间】:2016-07-24 23:41:09
【问题描述】:

这是一个查询,作为转换的一部分,我必须使用它作为基于特定条件从 Oracle 11i 提取收据的一部分。

--> 一项重要的检查是检查搁置的发票。我只需要提取发票被搁置的详细信息。并且检查的条件是

在 AP_HOLDS_ALL 表中 -- 1) 发票应该存在 2) 发布查找代码应为 NULL 3) 状态标志应该是 S 或 NULL 并且 4) AP_HOLDS_ALL 表中不应存在具有相同发票 ID 且发布查找代码不为空的任何行。

我已尝试在以下查询的最后一个中添加以下条件,但它获取行的速度非常慢(一天 100 000 条记录)。

如何提高性能?

    select * -- multiple Columns
    from rcv_shipment_headers  rsh,
   rcv_shipment_lines    rsl,
   rcv_transactions      rt,
   hr_operating_units    hou,
   po_headers_all        poh,
   po_lines_all          pol,
   po_line_locations_all pll,
   po_distributions_all  pda,
   po_vendors            pv,
   po_vendor_sites_all   pvs
    where 1 = 1
and rsh.shipment_header_id = rsl.shipment_header_id
and rsh.shipment_header_id = rt.shipment_header_id
and rsl.shipment_line_id = rt.shipment_line_id
and rt.po_header_id = poh.po_header_id
and rt.po_line_id = pol.po_line_id
and rt.po_line_location_id = pll.line_location_id
and rt.po_distribution_id = pda.po_distribution_id
and poh.po_header_id = pol.po_header_id
and pol.po_line_id = pll.po_line_id
and pll.line_location_id = pda.line_location_id
and poh.org_id = hou.organization_id
and poh.type_lookup_code = 'STANDARD'
and poh.authorization_status = 'APPROVED'
and poh.approved_flag = 'Y'
and rsh.ship_to_org_id = pll.ship_to_organization_id
and rt.organization_id = pll.ship_to_organization_id
and pol.org_id = hou.organization_id
and pll.org_id = hou.organization_id
and pda.org_id = hou.organization_id
and hou.date_to is null
and (rt.transaction_type = 'DELIVER' or rt.transaction_type = 'RECEIVE')
and rt.vendor_site_id = pvs.vendor_site_id
and rt.vendor_id = pv.vendor_id
and pv.vendor_id = pvs.vendor_id
and (nvl(pda.quantity_ordered, 0) - nvl(pda.quantity_cancelled, 0)) > 0
and nvl(pda.quantity_delivered, 0) > 0
and nvl(pda.quantity_billed, 0) > 0
and nvl(rsl.quantity_received, 0) > 0
and ((nvl(pda.quantity_delivered, 0) = nvl(pda.quantity_billed, 0)) or
    (nvl(pda.quantity_delivered, 0) > nvl(pda.quantity_billed, 0)) or
   (nvl(pda.quantity_delivered, 0) < nvl(pda.quantity_billed, 0)))

and exists
 (select aida.po_distribution_id
      from ap_invoices_all aia, ap_invoice_distributions_all aida
     where aia.cancelled_date is null
       and aida.po_distribution_id = pda.po_distribution_id
       and exists
     (select c.invoice_id
              from ap_holds_all c
             where c.release_lookup_code is null
               and c.invoice_id = aia.invoice_id
               and c.org_id = nvl(p_leg_operating_unit, c.org_id)
               and (c.status_flag = 'S' or c.status_flag is null)
               and not exists
             (select 1
                      from ap_holds_all d
                     where d.invoice_id = c.invoice_id
                       and d.org_id = nvl(p_leg_operating_unit, d.org_id)
                       and d.release_lookup_code is not null))
         and aia.org_id = nvl(p_leg_operating_unit, aia.org_id)
         and aia.invoice_id = aida.invoice_id)
   and poh.org_id = nvl(p_leg_operating_unit, poh.org_id)
  • p_leg_operating_unit 是一个具有 NULL 值的参数,因为我正在尝试获取所有 OU 的值

** last exists 导致问题。

【问题讨论】:

  • 你能试试并行执行吗? SELECT /*+ PARALLEL(4) */ * from ...
  • 谢谢..让我试试..我会发布结果。
  • 我尝试了并行,但它不起作用。事实上,它增加了查询的成本

标签: sql oracle optimization oracle10g po


【解决方案1】:

尝试以下方法,可能会解决您的问题:

  1. /*+ 并行(4) */ --hint.如果不起作用,请尝试 并行(8)/并行(16)。
  2. 重新排序连接。根据返回的最少行数连接表。例如表 A,B,C 。加入 a & b 返回 100 行,但 B&c 返回 20 行。然后首先加入B&C表并加入 与 A.
  3. 如果优化器不访问索引,则使用 /*+ Index * 提示。

【讨论】:

  • 感谢 Sathish 的帮助,但我尝试使用索引或并行进行重组。它不会加快查询速度。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-17
  • 2017-06-22
  • 2020-07-30
  • 2017-01-24
相关资源
最近更新 更多