Query Execution plan too long

  • Hi All,

    I am working on a legacy application and one of the view has degraded performance. I have to fix it,

    but the query execution makes me mad as it is a very lengthy plan. Is there an alternative way to understand the plan?

  • Have you tried a 3rd party tool like SQL Sentry?

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • NO because they wont allow to install 3rd party tools

  • I bet if you post the plan here that we can take a look at it and get an idea of what is killing your performance.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • thenewbee (7/22/2015)


    NO because they wont allow to install 3rd party tools

    If no 3rd party tools are allowed, you're stuck with the 3 versions of execution plans (plain text, xml, graphic).

    As Alan said, you could share the plan and we could try to identify the problem.

    You could also go step by step trying to identify the problems. Remember that GUI plans are read right to left and bottom to top and that xml and graphic plans are exactly the same with a different interface, so you can check both "side to side".

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Luis Cazares (7/23/2015)


    Remember that GUI plans are read right to left.

    Left-to-right to see the control flow.

    Right-to-left to see the data flow.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Hi thenewbee,

    I have to review developpers' code in my new role hence I decided to read the ebook:

    SQL Server Execution Plans, Second Edition by Grant Fritchey

    http://www.sqlservercentral.com/articles/books/94937/

    It is very helpful !

    In your case I would say to you that you have ensure to use all the features available.

    I don't know your level nor if you have read it already however I suggest you have a look at the short paragraph:

    Chapter 8: Advanced Topics

    Reading Large-scale Execution Plans

    It tells:

    "Click on the plus sign to open a little window, showing a representation of the entire

    execution plan. Keep your mouse button depressed, and drag the cursor across the

    window. You'll see that this moves a small "viewing rectangle" around the plan,"

    I hope it'll help you.

    Good luck.

  • Sorry that I couldn't post my plan here. I agree to Luis C. and decided to go step by step.

    I wanted some experts commenting how to analyze a very big lengthy plan.( my first lengthy plan)

    But I found XML plan very difficult to understand and found very difficult to find CPU time and table scan ( i actually searched table scan)

  • Thanks for sharing the link

  • Don't try reading the XML plan. Use the graphical one.

    You won't find CPU time in the plan. You'll find costs, but they aren't times and can't be used to do anything other than compare to other operators or plans (and they're estimates)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • thenewbee (7/23/2015)


    Sorry that I couldn't post my plan here. I agree to Luis C. and decided to go step by step.

    I wanted some experts commenting how to analyze a very big lengthy plan.( my first lengthy plan)

    But I found XML plan very difficult to understand and found very difficult to find CPU time and table scan ( i actually searched table scan)

    I periodically have to look at some pretty huge plans for poorly performing queries - there's a science to it and I'm still learning. The first thing I look for is the thing that's using the most resources E.g. If I see a sort with a 96% on it - I have often narrowed down the problem. But it's often not that easy. It's not advantageous to look at everything but there's are a lot of red-flag things I look for in addition to Table Scans such as lazy spools and big Sorts, especially one's with a yellow exclamation point - often an indication that memory is spilling onto the temp db. When you see an exclamation point on any event - it' worth investigating further. For Index Scans/seeks I like to hover over and compare the estimated vs actual rows, huge discrepancies might mean that your stats are out of date or you are experiencing parameter sniffing.

    Maxime mentioned Grants Query Plan book which is excellent. I also highly recommend

    Inside the SQL Server Query Optimizer by Benjamin Nevarez. It's a great book.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Alan.B (7/23/2015)


    Maxime mentioned Grants Query Plan book which is excellent. I also highly recommend

    Inside the SQL Server Query Optimizer by Benjamin Nevarez. It's a great book.

    These one is definitely in my reading list.

    Thanks for pointing it out, maybe I should consider putting it at the top of it then. 🙂

    Aside this (and out of subject, sorry about it) I would recommend to read How to become an Exceptional DBA

    http://www.red-gate.com/community/books/exceptional-dba-book

    This is about an exceptionnal DBA explaining the path on how to become an exceptionnal DBA. This book makes you want to know everything about SQL Server and to be recognized in the community. 😉

    Max.

  • Attached a test plan, Is it possible to avoid the table scan & clustered index scan in this scenario

  • thenewbee (7/26/2015)


    Attached a test plan, Is it possible to avoid the table scan & clustered index scan in this scenario

    Yes. Create covering indexes for both tables, something like this:

    CREATE INDEX ix_member_no ON dbo.member (member_no) INCLUDE (lastname)

    CREATE INDEX ix_member_no ON dbo.payment (member_no) INCLUDE (payment_no, payment_dt, payment_amt)

    No. Sql Server will still have to do a complete scan of these new indexes because your query returns every row from both tables.

    The payment table is a heap i.e. it has no clustered index, and the clustered index on the member table may not be the best choice. If you're interested in advancing your knowledge of SQL Server indexes, then David Durant's series [/url]is a great place to start.


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

  • thenewbee (7/22/2015)


    Hi All,

    I am working on a legacy application and one of the view has degraded performance. I have to fix it,

    but the query execution makes me mad as it is a very lengthy plan. Is there an alternative way to understand the plan?

    Post it up. Folks are likely to recommend points in the query where it can be broken down into functional blocks, possibly using #temp tables.


    [font="Arial"]Low-hanging fruit picker and defender of the moggies[/font]

    For better assistance in answering your questions, please read this[/url].


    Understanding and using APPLY, (I)[/url] and (II)[/url] Paul White[/url]

    Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic. Login to reply