TSQL Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • martin_rendell@hotmail.com

    TSQL Help

    A stored procedure was running slowly so I took the code, removed the
    subselect and included a join, then took the max and included as part
    of a correlated subquery.

    The result is below, however, this is no improvement over the original.
    An advice would be greatly appreciated.

    SELECT FSALT.FUNDING_L INE_TYPE_ID,
    A.PAYMENT_PERIO D_ID,
    A.CASH AS CASH,
    A.VOLUME AS VOLUME
    FROM ACTUALS A
    INNER JOIN (SELECT MAX(COLLECTION_ PAYMENT_PERIOD_ ­ID) AS CPP FROM
    ACTUALS ACT WHERE COLLECTION_PAYM ENT_PERIOD_ID<= ­456) AS O ON O.CPP =
    A.COLLECTION_PA YMENT_PERIOD_ID
    INNER JOIN FS_ACTUAL_LINE_ TYPES FSALT ON FSALT.FS_ACTUAL _LINE_TYPE_ID =

    A.FS_ACTUAL_LIN E_TYPE_ID
    INNER JOIN PAYMENT_PERIODS PP ON PP.PAYMENT_PERI OD_ID =
    A.PAYMENT_PERIO D_ID
    WHERE
    A.ORG_ID=24771
    AND A.LSC_ORG_ID=58 16
    AND PP.FUNDING_STRE AM_ID=5
    AND PP.FUNDING_PERI OD_ID=6
    GROUP BY
    FSALT.FUNDING_L INE_TYPE_ID,
    A.PAYMENT_PERIO D_ID,
    A.CASH,
    A.VOLUME

  • Chandra

    #2
    Re: TSQL Help

    hi
    try to implement index on COLLECTION_PAYM ENT_PERIOD_ID
    this might improve the performance of ur query

    best Regards,
    Chandra
    米兰平台(中国)ios/安卓版/手机app下载,拥有快速刺激的游戏体验,场景精美,动画生动,玩法丰富,节奏明快。传统玩法+全新模式,多元化游戏体验精彩刺激,引爆通往财富的大门。将秉承“依法治企,诚信合作,求精务实,开拓创新”的宗旨,发扬“金塔机械,真诚装备”的价值追求,精心培育自主知识产权核心竞争优势,坚持精细化管理,打造轻工、化工设备高质量品牌,谋求企业与社会的共同发展。

    Find the queries, documents, syntaxes, techniques in using MS SQL Server in an effecient way. I will try to collect maximum information and postit on the site.

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

    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    • Erland Sommarskog

      #3
      Re: TSQL Help

      martin_rendell@ hotmail.com (martin_rendell @hotmail.com) writes:[color=blue]
      > A stored procedure was running slowly so I took the code, removed the
      > subselect and included a join, then took the max and included as part
      > of a correlated subquery.
      >
      > The result is below, however, this is no improvement over the original.
      > An advice would be greatly appreciated.[/color]

      Without knowledge of the tables and index, and what sizes they are, it
      is impossible to say "fix this!". It could be that you need a new index.
      It could be that statistics are poor. It could be that everything is up
      to shape, but the optimizer makes an incorrect estimate.

      What you can do on your own, is to put the query from Query Analyzer and
      press CTRL-L. This gives you the estimated execution plan.

      However, if this code is in a stored procedure, I suspect that several of
      the numbers below are parameters or variables. This has an impact on the
      query plan. In such case, it is better to run the stored procedure, and
      prior that press CTRL-K to get the actual execution plan.

      Once you have the execution plan, you might be able to make some findings.

      If you can't make it out, please post:

      o CREATE TABLE statements for the tables.
      o CREATE INDEX statements for the tables.
      o Approx no of rows per table.
      o The output from SET STATIISTICS_PRO FILE ON. Run this command first,
      the procedure.



      --
      Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

      Books Online for SQL Server SP3 at
      Get the flexibility you need to use integrated solutions, apps, and innovations in technology with your data, wherever it lives—in the cloud, on-premises, or at the edge.


      Comment

      Working...