Auf Thema antworten

Guten Morgen :)


ich habe eine Tabellenwertfunktion in der nach bestimmten parametern verträge gefiltert werden, zusätzliche informationen aus anderen tabellen hinzugefügt werden und zu produkten, die jeweils einem vertrag zugeordnet sind, aktuelle marktpreise gesucht werden.


vorab: die parameter beim test sind immer gleich!


die funktion OHNE die marktpreissuche (auskommentiert) liefert 20209 datensätze und dauert 9sec.

nur die abfrage für die marktpreissuche liefert 726 datensätze  < 1sec.


problem ist folgendes:


sobald ich die marktpreisabfrage in der funktion mitausführen lasse und die preise mit einem innerjoin verknüpfe, dauert die abfrage mehrere minuten.

in dem join werden die produkt-id sowie die zwei datums-felder (monatsweise) datumVon und datumBis abgefragt.


ich habe leider keine ahnung, warum der so lange braucht :/


in der originalen query frage ich natürlich die felder ab, die ich brauche. hier habe ich zur vereinfachung select * genommen.


[CODE]        select *

        from BundO.dbo.tbl_BC_BoerseIndexZemda_Mapping mapping

      

            --------------------------------------------------------------------------------

            -- Produkte auf die Produkt-ID der Mapping-Tabelle mappen

            inner join ZEMDA.dbo.tbl_product prod

                on (prod.product_id = mapping.Zemda_Produkt_ID)

            --------------------------------------------------------------------------------


            --------------------------------------------------------------------------------

            -- Produkt-Namen

            inner join EAC.dbo.tbl_BoersenPreiseStamm bps

                on (mapping.Boerse_ID = bps.Boerse_ID and mapping.Index_ID = bps.Index_ID)

            --------------------------------------------------------------------------------


            --------------------------------------------------------------------------------

            -- Verträge

            inner join Transfer.PFDB.qry_List_Contracts con

                on (con.Boerse_ID = mapping.Boerse_ID and con.Index_ID = mapping.Index_ID)

            --------------------------------------------------------------------------------


            --------------------------------------------------------------------------------

            -- Monatsscheiben der einzelnen Verträge

            inner join Transfer.PFDB.tbl_Monthly_Delivery_Values monthly

                on (con.Contract_No = monthly.Contract_No and con.Contract_Pos = monthly.Contract_Pos)

            --------------------------------------------------------------------------------


            ------------------------------------------------------------------------------------

            ---- Margin auf Vertragnummer mappen

            left outer join EPOS_40_Tage_DB.RAW.tbl_Margin mrg

                on con.Contract_No = mrg.VNr

            ------------------------------------------------------------------------------------


            ----------------------------------------------------------------------------------

            -- Bank auf den Namen mappen

            left outer join EPOS_40_Tage_DB.RAW.tbl_Banken bank

                on con.Bank_ID = bank.BankID

            ----------------------------------------------------------------------------------


            ----------------------------------------------------------------------------------

            -- Euro-Umrechnung auf die Bankwährung

            left outer join EPOS_40_Tage_DB.RAW.tbl_EuroUmrechnung eur

                on con.Ccy_ID = eur.Waehrung_ID

          

            left outer join EPOS_40_Tage_DB.RAW.tbl_EuroUmrechnung umr

                on bank.Währung = umr.Waehrung_ID

            ----------------------------------------------------------------------------------

          

            ----------------------------------------------------------------------------------

            -- Broker auf BrokerID

            left outer join EPOS_40_Tage_DB.RAW.tbl_Broker brk

                on con.Broker_ID_1 = brk.Broker_ID

      


      

            ------------------------------------------------------------------------------------

            -- Preis auf ProduktID mappen

            inner join (select priceMain.price, maxdate.date_from, maxdate.date_to, maxdate.maxdate, maxdate.product_id from ZEMDA.dbo.tbl_price priceMain

                            inner join (

                                        select price.product_id, price.date_from, price.date_to, max(price.trading_day) maxdate from ZEMDA.dbo.tbl_price price


                                        where 1=1

                                            and price.product_id in (select Zemda_Produkt_Id from BundO.dbo.tbl_BC_BoerseIndexZemda_Mapping)

                                            and price.trading_day <= @stand

                                            and price.date_from <= @DatBis

                                            and price.date_to >= @DatVon


                                        group by price.product_id, price.date_from, price.date_to

                                    ) maxdate

                                on (

                                        priceMain.product_id = maxdate.product_id

                                        and priceMain.date_from = maxdate.date_from

                                        and priceMain.date_to = maxdate.date_to

                                        and priceMain.trading_day = maxdate.maxdate

                    )) maxprice

                on (

                        mapping.Zemda_Produkt_ID = maxprice.prodid

                        --and con.contract_date = maxprice.maxdate

                        and monthly.Delivery_Month_From = maxprice.datefrom

                        and monthly.Delivery_Month_To = maxprice.dateto

                    )

            ------------------------------------------------------------------------------------



        where 1=1

        --    ----------------------------------------------------------------------------------

        --    -- Verträge

            and con.Option_CM_Ind = 0 --keine Optionen

            and con.VPP_Ind <> 2 --keine Fahrplanverträge

            and con.Contract_No > 0 --keine 'internen' Geschäfte

            and con.Boerse_ID > 0 and con.Index_ID > 0

            and con.Contract_Status_Ind = 1 --nur aktive Verträge

            and (

                con.Clearing_Ind = 1

                or con.CSA_Ind = 1 --(con.Clearing_Ind = 0 and bart.Bezeichnung = 'Credit Support Annex')

                or upper(con.Contract_Type) = 'CLEARED FX'

                )

            and con.Contract_Date between @HDatumV and @HDatumB -- Handelstag begrenzen

            and (

                    con.Buy_Sell_Ind = @Kauf

                    or con.Buy_Sell_Ind = @Verkauf

                  )

            ----------------------------------------------------------------------------------

            -- Monatsscheiben

            and monthly.Delivery_Month_To between @DatVon and @DatBis

            ----------------------------------------------------------------------------------

            -- Bank

            and con.Bank_ID = case @BankID when 0 then con.Bank_ID else @BankID end          

            ----------------------------------------------------------------------------------

            -- Margins

            and isnull(mrg.LKZ,0) = 0

            and isnull(mrg.abgeschlossen,'19000101')  = '19000101'

            and cast(monthly.Delivery_Month_From as datetime) >  isnull(mrg.Monatabgeschlossen,'19000101')  -- Vereinbarungsdatum > ...

            ----------------------------------------------------------------------------------[/CODE]


hat jemand ne idee, wie ich das problem beseitigen kann?


danke im voraus und schon mal ein schönes wochenende :)


lg


kraeppy


Zurück
Oben