Как ускорить работу базы данных DB2 IBM iSeries с помощью Entity Framework - PullRequest
0 голосов
/ 14 октября 2019

В настоящее время я изучаю проект, в котором внутренним компонентом является база данных IBM iSeries DB2, а внешним интерфейсом является MVC с Entity Framework. На данный момент код использует запросы LINQ для получения данных из базы данных. Некоторые из этих операций занимают ужасно много времени. Мне дали задание ускорить вещи, если это возможно.

Мой план состоит в том, чтобы создать хранимые процедуры и использовать инфраструктуру сущностей для вызова хранимых процедур. Также я могу многократно использовать эти хранимые процедуры в других проектах. Ребята, у вас есть какие-либо предложения по этой идее?

В качестве теста я выбрал один из запросов Linq, который долго выполнялся, и извлек SQL, который использует Entity Framework.

Я создал хранимую процедуру с помощью этого скрипта (я жестко закодировал все значения параметров, чтобы SP не принимал никаких параметров). Когда я пытаюсь сравнить мой вызов sp в Visual Studio 2019, неожиданно запрос Linq оказался быстрее, чем использование хранимой процедуры. Это потому, что хранимая процедура не оптимизирована, поскольку я скопировал SQL, созданный структурой сущностей?

Любые предложения приветствуются.

Созданная мной хранимая процедура выглядит следующим образом

 CREATE PROCEDURE FMSLIBLE.SPNESGETNOTDECLAREDITEMS ( ) 
        DYNAMIC RESULT SETS 1 
        LANGUAGE SQL 
        SPECIFIC FMSLIBLE.SPNESGETNOTDECLAREDITEMS 
        NOT DETERMINISTIC 
        READS SQL DATA 
        CALLED ON NULL INPUT 
        SET OPTION  ALWBLK = *ALLREAD , 
        ALWCPYDTA = *OPTIMIZE , 
        COMMIT = *NONE , 
        CLOSQLCSR = *ENDACTGRP , 
        DECRESULT = (31, 31, 00) , 
        DFTRDBCOL = *NONE , 
        DLYPRP = *NO , 
        DYNDFTCOL = *NO , 
        DYNUSRPRF = *USER , 
        RDBCNNMTH = *RUW , 
        SRTSEQ = *HEX   
        BEGIN 

    DECLARE SQLSTATE CHAR ( 5 ) DEFAULT '00000' ; 
    DECLARE SQLCODE INTEGER DEFAULT 0 ; 
    DECLARE ERRORLABEL CHAR ( 32 ) DEFAULT '' ; 

    DECLARE X1 CURSOR WITH RETURN TO CLIENT FOR 
    SELECT 
    PROJECT4 . C1 AS C1 , 
    PROJECT4 . ROWID AS ROWID , 
    PROJECT4 . JOBNUMBER AS JOBNUMBER , 
    PROJECT4 . CREATED AS CREATED , 
    PROJECT4 . EMMOVN AS EMMOVN , 
    PROJECT4 . CREATEDNUM AS CREATEDNUM , 
    PROJECT4 . EMIORE AS EMIORE , 
    PROJECT4 . EMCONS AS EMCONS , 
    PROJECT4 . UK_IMP_EXP_NAME AS UK_IMP_EXP_NAME , 
    PROJECT4 . AIRPORT_NAME AS AIRPORT_NAME , 
    PROJECT4 . BACKTOBACKMARKER AS BACKTOBACKMARKER , 
    PROJECT4 . LINESHIPMENT AS LINESHIPMENT , 
    PROJECT4 . POSTFLIGHTMARKER AS POSTFLIGHTMARKER , 
    PROJECT4 . CUSTOMSTRANSSTATUS AS CUSTOMSTRANSSTATUS , 
    PROJECT4 . ORIGIN AS ORIGIN , 
    PROJECT4 . DESTIN AS DESTIN , 
    PROJECT4 . SHIPMNTCATEGORY AS SHIPMNTCATEGORY , 
    PROJECT4 . COLOAD_AGENT_NAME AS COLOAD_AGENT_NAME , 
    PROJECT4 . TOTAL_PACKAGES AS TOTAL_PACKAGES , 
    PROJECT4 . LINEDESCRIPTIONS AS LINEDESCRIPTIONS , 
    PROJECT4 . TOTWEIGHT AS TOTWEIGHT , 
    PROJECT4 . TOTCUBE AS TOTCUBE , 
    PROJECT4 . TOTVOLUME AS TOTVOLUME , 
    PROJECT4 . SHIPPEDDATE AS SHIPPEDDATE , 
    PROJECT4 . SHIPPED AS SHIPPED , 
    PROJECT4 . FLIGHTPART1 AS FLIGHTPART1 , 
    PROJECT4 . FLIGHTPART2 AS FLIGHTPART2 , 
    PROJECT4 . FLIGHT2PART1 AS FLIGHT2PART1 , 
    PROJECT4 . FLIGHT2PART2 AS FLIGHT2PART2 , 
    PROJECT4 . FLIGHT2DATENUM AS FLIGHT2DATENUM , 
    PROJECT4 . ACTUALFLIGHT1 AS ACTUALFLIGHT1 , 
    PROJECT4 . ACTUALFLIGHT2 AS ACTUALFLIGHT2 , 
    PROJECT4 . ACTUALFLIGHTDATENUM AS ACTUALFLIGHTDATENUM , 
    PROJECT4 . ACTUALFLIGHTDATE AS ACTUALFLIGHTDATE , 
    PROJECT4 . AIRPORTORIGIN AS AIRPORTORIGIN , 
    PROJECT4 . AIRPORTARRIVAL AS AIRPORTARRIVAL , 
    PROJECT4 . AIRPORTDESTIN AS AIRPORTDESTIN , 
    PROJECT4 . AIRPORTTRANSIT AS AIRPORTTRANSIT , 
    PROJECT4 . AIRPORTFINALDESTIN AS AIRPORTFINALDESTIN , 
    PROJECT4 . FLIGHT1DAY AS FLIGHT1DAY , 
    PROJECT4 . FLIGHT2DAY AS FLIGHT2DAY , 
    PROJECT4 . UKIMPORTOREXPORTER AS UKIMPORTOREXPORTER , 
    PROJECT4 . SHIPPERCODE AS SHIPPERCODE , 
    PROJECT4 . FOREIGNSENDER AS FOREIGNSENDER , 
    PROJECT4 . FOREIGNNAME AS FOREIGNNAME , 
    PROJECT4 . JOBCANCELLED AS JOBCANCELLED , 
    PROJECT4 . JOBDELETED AS JOBDELETED , 
    PROJECT4 . MASTERAIRWAYBILLPREFIX AS MASTERAIRWAYBILLPREFIX , 
    PROJECT4 . MASTERAIRWAYBILLNUMBER AS MASTERAIRWAYBILLNUMBER , 
    PROJECT4 . EVALRECENT AS EVALRECENT , 
    PROJECT4 . TAGCOMPANY AS TAGCOMPANY , 
    PROJECT4 . TAGADCODE AS TAGADCODE , 
    PROJECT4 . TAGSEQUOIA AS TAGSEQUOIA 
    FROM LATERAL ( SELECT 
        PROJECT1 . ROWID AS ROWID , 
        PROJECT1 . JOBNUMBER AS JOBNUMBER , 
        PROJECT1 . CREATED AS CREATED , 
        PROJECT1 . EMMOVN AS EMMOVN , 
        PROJECT1 . CREATEDNUM AS CREATEDNUM , 
        PROJECT1 . EMIORE AS EMIORE , 
        PROJECT1 . EMCONS AS EMCONS , 
        PROJECT1 . UK_IMP_EXP_NAME AS UK_IMP_EXP_NAME , 
        PROJECT1 . AIRPORT_NAME AS AIRPORT_NAME , 
        PROJECT1 . BACKTOBACKMARKER AS BACKTOBACKMARKER , 
        PROJECT1 . LINESHIPMENT AS LINESHIPMENT , 
        PROJECT1 . POSTFLIGHTMARKER AS POSTFLIGHTMARKER , 
        PROJECT1 . CUSTOMSTRANSSTATUS AS CUSTOMSTRANSSTATUS , 
        PROJECT1 . ORIGIN AS ORIGIN , 
        PROJECT1 . DESTIN AS DESTIN , 
        PROJECT1 . SHIPMNTCATEGORY AS SHIPMNTCATEGORY , 
        PROJECT1 . COLOAD_AGENT_NAME AS COLOAD_AGENT_NAME , 
        PROJECT1 . TOTAL_PACKAGES AS TOTAL_PACKAGES , 
        PROJECT1 . LINEDESCRIPTIONS AS LINEDESCRIPTIONS , 
        PROJECT1 . TOTWEIGHT AS TOTWEIGHT , 
        PROJECT1 . TOTCUBE AS TOTCUBE , 
        PROJECT1 . TOTVOLUME AS TOTVOLUME , 
        PROJECT1 . SHIPPEDDATE AS SHIPPEDDATE , 
        PROJECT1 . SHIPPED AS SHIPPED , 
        PROJECT1 . FLIGHTPART1 AS FLIGHTPART1 , 
        PROJECT1 . FLIGHTPART2 AS FLIGHTPART2 , 
        PROJECT1 . FLIGHT2PART1 AS FLIGHT2PART1 , 
        PROJECT1 . FLIGHT2PART2 AS FLIGHT2PART2 , 
        PROJECT1 . FLIGHT2DATENUM AS FLIGHT2DATENUM , 
        PROJECT1 . ACTUALFLIGHT1 AS ACTUALFLIGHT1 , 
        PROJECT1 . ACTUALFLIGHT2 AS ACTUALFLIGHT2 , 
        PROJECT1 . ACTUALFLIGHTDATENUM AS ACTUALFLIGHTDATENUM , 
        PROJECT1 . ACTUALFLIGHTDATE AS ACTUALFLIGHTDATE , 
        PROJECT1 . AIRPORTORIGIN AS AIRPORTORIGIN , 
        PROJECT1 . AIRPORTARRIVAL AS AIRPORTARRIVAL , 
        PROJECT1 . AIRPORTDESTIN AS AIRPORTDESTIN , 
        PROJECT1 . AIRPORTTRANSIT AS AIRPORTTRANSIT , 
        PROJECT1 . AIRPORTFINALDESTIN AS AIRPORTFINALDESTIN , 
        PROJECT1 . FLIGHT1DAY AS FLIGHT1DAY , 
        PROJECT1 . FLIGHT2DAY AS FLIGHT2DAY , 
        PROJECT1 . UKIMPORTOREXPORTER AS UKIMPORTOREXPORTER , 
        PROJECT1 . SHIPPERCODE AS SHIPPERCODE , 
        PROJECT1 . FOREIGNSENDER AS FOREIGNSENDER , 
        PROJECT1 . FOREIGNNAME AS FOREIGNNAME , 
        PROJECT1 . JOBCANCELLED AS JOBCANCELLED , 
        PROJECT1 . JOBDELETED AS JOBDELETED , 
        PROJECT1 . MASTERAIRWAYBILLPREFIX AS MASTERAIRWAYBILLPREFIX , 
        PROJECT1 . MASTERAIRWAYBILLNUMBER AS MASTERAIRWAYBILLNUMBER , 
        PROJECT1 . EVALRECENT AS EVALRECENT , 
        PROJECT1 . C1 AS C1 , 
        PROJECT1 . TAGCOMPANY AS TAGCOMPANY , 
        PROJECT1 . TAGADCODE AS TAGADCODE , 
        PROJECT1 . TAGSEQUOIA AS TAGSEQUOIA 
        FROM LATERAL ( SELECT 
            EXTENT1 . ROWID AS ROWID , 
            EXTENT1 . JOBNUMBER AS JOBNUMBER , 
            EXTENT1 . CREATED AS CREATED , 
            EXTENT1 . EMMOVN AS EMMOVN , 
            EXTENT1 . CREATEDNUM AS CREATEDNUM , 
            EXTENT1 . EMIORE AS EMIORE , 
            EXTENT1 . EMCONS AS EMCONS , 
            EXTENT1 . UK_IMP_EXP_NAME AS UK_IMP_EXP_NAME , 
            EXTENT1 . AIRPORT_NAME AS AIRPORT_NAME , 
            EXTENT1 . BACKTOBACKMARKER AS BACKTOBACKMARKER , 
            EXTENT1 . LINESHIPMENT AS LINESHIPMENT , 
            EXTENT1 . POSTFLIGHTMARKER AS POSTFLIGHTMARKER , 
            EXTENT1 . CUSTOMSTRANSSTATUS AS CUSTOMSTRANSSTATUS , 
            EXTENT1 . ORIGIN AS ORIGIN , 
            EXTENT1 . DESTIN AS DESTIN , 
            EXTENT1 . SHIPMNTCATEGORY AS SHIPMNTCATEGORY , 
            EXTENT1 . COLOAD_AGENT_NAME AS COLOAD_AGENT_NAME , 
            EXTENT1 . TOTAL_PACKAGES AS TOTAL_PACKAGES , 
            EXTENT1 . LINEDESCRIPTIONS AS LINEDESCRIPTIONS , 
            EXTENT1 . TOTWEIGHT AS TOTWEIGHT , 
            EXTENT1 . TOTCUBE AS TOTCUBE , 
            EXTENT1 . TOTVOLUME AS TOTVOLUME , 
            EXTENT1 . SHIPPEDDATE AS SHIPPEDDATE , 
            EXTENT1 . SHIPPED AS SHIPPED , 
            EXTENT1 . FLIGHTPART1 AS FLIGHTPART1 , 
            EXTENT1 . FLIGHTPART2 AS FLIGHTPART2 , 
            EXTENT1 . FLIGHT2PART1 AS FLIGHT2PART1 , 
            EXTENT1 . FLIGHT2PART2 AS FLIGHT2PART2 , 
            EXTENT1 . FLIGHT2DATENUM AS FLIGHT2DATENUM , 
            EXTENT1 . ACTUALFLIGHT1 AS ACTUALFLIGHT1 , 
            EXTENT1 . ACTUALFLIGHT2 AS ACTUALFLIGHT2 , 
            EXTENT1 . ACTUALFLIGHTDATENUM AS ACTUALFLIGHTDATENUM , 
            EXTENT1 . ACTUALFLIGHTDATE AS ACTUALFLIGHTDATE , 
            EXTENT1 . AIRPORTORIGIN AS AIRPORTORIGIN , 
            EXTENT1 . AIRPORTARRIVAL AS AIRPORTARRIVAL , 
            EXTENT1 . AIRPORTDESTIN AS AIRPORTDESTIN , 
            EXTENT1 . AIRPORTTRANSIT AS AIRPORTTRANSIT , 
            EXTENT1 . AIRPORTFINALDESTIN AS AIRPORTFINALDESTIN , 
            EXTENT1 . FLIGHT1DAY AS FLIGHT1DAY , 
            EXTENT1 . FLIGHT2DAY AS FLIGHT2DAY , 
            EXTENT1 . UKIMPORTOREXPORTER AS UKIMPORTOREXPORTER , 
            EXTENT1 . SHIPPERCODE AS SHIPPERCODE , 
            EXTENT1 . FOREIGNSENDER AS FOREIGNSENDER , 
            EXTENT1 . FOREIGNNAME AS FOREIGNNAME , 
            EXTENT1 . JOBCANCELLED AS JOBCANCELLED , 
            EXTENT1 . JOBDELETED AS JOBDELETED , 
            EXTENT1 . MASTERAIRWAYBILLPREFIX AS MASTERAIRWAYBILLPREFIX , 
            EXTENT1 . MASTERAIRWAYBILLNUMBER AS MASTERAIRWAYBILLNUMBER , 
            EXTENT1 . EVALRECENT AS EVALRECENT , 
            CAST ( 1 AS INT ) AS C1 , 
            EXTENT2 . TAGCOMPANY AS TAGCOMPANY , 
            EXTENT2 . TAGADCODE AS TAGADCODE , 
            EXTENT2 . TAGSEQUOIA AS TAGSEQUOIA 
            FROM ( SELECT 
    VEMASTEREXPORT . ROWID AS ROWID , 
    VEMASTEREXPORT . JOBNUMBER AS JOBNUMBER , 
    VEMASTEREXPORT . CREATED AS CREATED , 
    VEMASTEREXPORT . EMMOVN AS EMMOVN , 
    VEMASTEREXPORT . CREATEDNUM AS CREATEDNUM , 
    VEMASTEREXPORT . EMIORE AS EMIORE , 
    VEMASTEREXPORT . EMCONS AS EMCONS , 
    VEMASTEREXPORT . UK_IMP_EXP_NAME AS UK_IMP_EXP_NAME , 
    VEMASTEREXPORT . AIRPORT_NAME AS AIRPORT_NAME , 
    VEMASTEREXPORT . BACKTOBACKMARKER AS BACKTOBACKMARKER , 
    VEMASTEREXPORT . LINESHIPMENT AS LINESHIPMENT , 
    VEMASTEREXPORT . POSTFLIGHTMARKER AS POSTFLIGHTMARKER , 
    VEMASTEREXPORT . CUSTOMSTRANSSTATUS AS CUSTOMSTRANSSTATUS , 
    VEMASTEREXPORT . ORIGIN AS ORIGIN , 
    VEMASTEREXPORT . DESTIN AS DESTIN , 
    VEMASTEREXPORT . SHIPMNTCATEGORY AS SHIPMNTCATEGORY , 
    VEMASTEREXPORT . COLOAD_AGENT_NAME AS COLOAD_AGENT_NAME , 
    VEMASTEREXPORT . TOTAL_PACKAGES AS TOTAL_PACKAGES , 
    VEMASTEREXPORT . LINEDESCRIPTIONS AS LINEDESCRIPTIONS , 
    VEMASTEREXPORT . TOTWEIGHT AS TOTWEIGHT , 
    VEMASTEREXPORT . TOTCUBE AS TOTCUBE , 
    VEMASTEREXPORT . TOTVOLUME AS TOTVOLUME , 
    VEMASTEREXPORT . SHIPPEDDATE AS SHIPPEDDATE , 
    VEMASTEREXPORT . SHIPPED AS SHIPPED , 
    VEMASTEREXPORT . FLIGHTPART1 AS FLIGHTPART1 , 
    VEMASTEREXPORT . FLIGHTPART2 AS FLIGHTPART2 , 
    VEMASTEREXPORT . FLIGHT2PART1 AS FLIGHT2PART1 , 
    VEMASTEREXPORT . FLIGHT2PART2 AS FLIGHT2PART2 , 
    VEMASTEREXPORT . FLIGHT2DATENUM AS FLIGHT2DATENUM , 
    VEMASTEREXPORT . ACTUALFLIGHT1 AS ACTUALFLIGHT1 , 
    VEMASTEREXPORT . ACTUALFLIGHT2 AS ACTUALFLIGHT2 , 
    VEMASTEREXPORT . ACTUALFLIGHTDATENUM AS ACTUALFLIGHTDATENUM , 
    VEMASTEREXPORT . ACTUALFLIGHTDATE AS ACTUALFLIGHTDATE , 
    VEMASTEREXPORT . AIRPORTORIGIN AS AIRPORTORIGIN , 
    VEMASTEREXPORT . AIRPORTARRIVAL AS AIRPORTARRIVAL , 
    VEMASTEREXPORT . AIRPORTDESTIN AS AIRPORTDESTIN , 
    VEMASTEREXPORT . AIRPORTTRANSIT AS AIRPORTTRANSIT , 
    VEMASTEREXPORT . AIRPORTFINALDESTIN AS AIRPORTFINALDESTIN , 
    VEMASTEREXPORT . FLIGHT1DAY AS FLIGHT1DAY , 
    VEMASTEREXPORT . FLIGHT2DAY AS FLIGHT2DAY , 
    VEMASTEREXPORT . UKIMPORTOREXPORTER AS UKIMPORTOREXPORTER , 
    VEMASTEREXPORT . SHIPPERCODE AS SHIPPERCODE , 
    VEMASTEREXPORT . FOREIGNSENDER AS FOREIGNSENDER , 
    VEMASTEREXPORT . FOREIGNNAME AS FOREIGNNAME , 
    VEMASTEREXPORT . JOBCANCELLED AS JOBCANCELLED , 
    VEMASTEREXPORT . JOBDELETED AS JOBDELETED , 
    VEMASTEREXPORT . MASTERAIRWAYBILLPREFIX AS MASTERAIRWAYBILLPREFIX , 
    VEMASTEREXPORT . MASTERAIRWAYBILLNUMBER AS MASTERAIRWAYBILLNUMBER , 
    VEMASTEREXPORT . EVALRECENT AS EVALRECENT 
    FROM DTALIBLE . VEMASTEREXPORT AS VEMASTEREXPORT ) AS EXTENT1 
            LEFT OUTER JOIN ( SELECT 
    ADRSFILTAG . TAGCOMPANY AS TAGCOMPANY , 
    ADRSFILTAG . TAGADCODE AS TAGADCODE , 
    ADRSFILTAG . TAGSEQUOIA AS TAGSEQUOIA 
    FROM GENLIBLE . ADRSFILTAG AS ADRSFILTAG ) AS EXTENT2 ON EXTENT1 . SHIPPERCODE = EXTENT2 . TAGADCODE 
        ) AS PROJECT1 
        WHERE ( ( ( ( ( ( ( ( ( ( NOT EXISTS ( SELECT 
            CAST ( 1 AS INT ) AS C1 
            FROM GENLIBLE . NWNESJBF AS EXTENT3 
            WHERE EXTENT3 . NWJOBN = PROJECT1 . JOBNUMBER 
        ) ) AND ( NOT EXISTS ( SELECT 
            CAST ( 1 AS INT ) AS C1 
            FROM FMSLIBLE . SEQNESFILE1 AS EXTENT4 
            WHERE EXTENT4 . JOBNUMBER = PROJECT1 . JOBNUMBER 
        ) ) ) AND ( '' <> PROJECT1 . EMCONS ) ) AND ( 'C' <> PROJECT1 . JOBCANCELLED ) ) AND ( 'Y' <> PROJECT1 . POSTFLIGHTMARKER ) ) AND ( NOT ( PROJECT1 . JOBNUMBER LIKE '%XP%' ) ) ) AND ( 'D' <> PROJECT1 . JOBDELETED ) ) AND ( '' <> PROJECT1 . CUSTOMSTRANSSTATUS ) ) AND ( 'C' <> PROJECT1 . CUSTOMSTRANSSTATUS ) ) AND ( PROJECT1 . CREATED >= '01/01/2018' ) ) AND ( 'DTA' = PROJECT1 . TAGCOMPANY ) 
    ) AS PROJECT4 
    ORDER BY PROJECT4 . JOBNUMBER ASC ; 

    DECLARE EXIT HANDLER FOR NOT FOUND 
    SIGNAL SQLSTATE VALUE '38200' SET MESSAGE_TEXT = '100: NO DATA FOUND' ; 

    DECLARE EXIT HANDLER FOR SQLEXCEPTION 
    SIGNAL SQLSTATE VALUE SQLSTATE SET MESSAGE_TEXT = ERRORLABEL ; 

    -- to return result set, do not CLOSE cursor 
    SET ERRORLABEL = 'OPEN CURSOR' ; 
    OPEN X1 ; 

    END  ; 

    GRANT ALTER , EXECUTE   
    ON SPECIFIC PROCEDURE FMSLIBLE.SPNESGETNOTDECLAREDITEMS 
    TO DMCLUSTER WITH GRANT OPTION ; 

    GRANT ALTER , EXECUTE   
    ON SPECIFIC PROCEDURE FMSLIBLE.SPNESGETNOTDECLAREDITEMS 
    TO P@A WITH GRANT OPTION ; 

    GRANT EXECUTE   
    ON SPECIFIC PROCEDURE FMSLIBLE.SPNESGETNOTDECLAREDITEMS 
    TO PUBLIC ;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...