2016-04-05 2 views
1

Dies ist eine Abfrage, die ich als Teil der Extraktion von Quittungen basierend auf bestimmten Bedingungen aus Oracle 11i als Teil der Konvertierung verwenden muss.Nicht in der Lage, eine SQL-Abfrage zu optimieren. Unter großen Kosten. Oracle Apps

-> Eine wichtige Überprüfung ist die Überprüfung auf zurückgestellte Rechnungen. Ich muss nur die Details herausziehen, in denen die Rechnungen gehalten werden. Und die Bedingung für die Überprüfung ist

In AP_HOLDS_ALL Tabelle - 1) die Rechnung sollte 2) Release-Lookup-Code existieren sollte 3) Status-Flag NULL sein sollte S oder NULL und 4) Es sollte keine Zeile existieren in der Tabelle AP_HOLDS_ALL mit der gleichen Rechnungs-ID und Release-Lookup-Code als nicht null.

Ich habe versucht und die folgenden Kriterien in der letzten der folgenden Abfrage hinzugefügt, aber es ruft die Zeilen sehr sehr langsam (100 000 Datensätze an einem Tag).

Wie kann man die Leistung verbessern?

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 ist ein Parameter, wie ich NULL-Wert wird mit bin versucht
  • die Werte für alle die OU

** zuletzt besteht das Problem verursacht zu bekommen.

+0

Können Sie die parallele Ausführung versuchen? SELECT/* + PARALLEL (4) */* von ... – Wolfgang

+0

Danke..Lass mich versuchen, dass .. Ich werde das Ergebnis veröffentlichen. –

+0

Ich versuchte mit parallel, aber es funktioniert nicht. In der Tat erhöht es die Kosten der Abfrage –

Antwort

-3

Versuchen Sie es mit der folgenden, kann Ihr Problem lösen:

  1. /* + parallel (4) */--hint. Wenn nicht funktioniert, versuchen Sie es mit parallel (8)/parallel (16).
  2. Ordnen Sie die Joins neu an. Verknüpfen Sie die Tabellen basierend auf der geringsten Anzahl zurückgegebener Zeilen. Für Beispiel Tabelle A, B, C. Join a & b gibt 100 Zeilen zurück, aber B & c gibt 20 Zeilen zurück. Dann zuerst verbinden B & C-Tabelle und Join mit A.
  3. Verwenden Sie/* + Index * Hinweis, wenn der Optimierer nicht auf Indizes zugreifen.
+0

Dank lassen Sie mich die Abfrage reorganisieren .. Ich werde das Ergebnis .. –

+0

Vielen Dank Sathish für Ihre Hilfe, aber ich habe versucht, reorganisieren, mit Index oder parallel. Es beschleunigt die Abfrage nicht. –