Running query with Actual Execution Plan On slows down the query?

  • when running a loing SQL Statement with Actual Plan On it takes 2 hours.
    if run without Actual Exec Plan it takes 20 minutes.
    Is it realistic that Execution Plan made SUCH a big difference?

    Likes to play Chess

  • VoldemarG - Monday, November 12, 2018 9:03 PM

    when running a loing SQL Statement with Actual Plan On it takes 2 hours.
    if run without Actual Exec Plan it takes 20 minutes.
    Is it realistic that Execution Plan made SUCH a big difference?

    It make a sight difference not some what you have, Can you post the code and plan.

    Muthukkumaran Kaliyamoorthy
    https://www.sqlserverblogforum.com/

  • VoldemarG - Monday, November 12, 2018 9:03 PM

    when running a loing SQL Statement with Actual Plan On it takes 2 hours.
    if run without Actual Exec Plan it takes 20 minutes.
    Is it realistic that Execution Plan made SUCH a big difference?

    Depending on the query, quite possible.  Some people have seen queries run forever before they cancelled them.

  • muthukkumaran Kaliyamoorthy - Monday, November 12, 2018 10:24 PM

    VoldemarG - Monday, November 12, 2018 9:03 PM

    when running a loing SQL Statement with Actual Plan On it takes 2 hours.
    if run without Actual Exec Plan it takes 20 minutes.
    Is it realistic that Execution Plan made SUCH a big difference?

    It make a sight difference not some what you have, Can you post the code and plan.

    Well.. it is a query that within the cursor selects 50 000 times from the view that selects from the other view that selects from 5 other nested views...
    We are OK with the query running 20 minutes. I was still thinking that I can improve it by cutting another 10 minutes but its not critical. May be the query plan is so huge that it really slows down the execution of this code so noticeably. I have attached the code but have no idea how to get rid of this cursor...

    Likes to play Chess

  • VoldemarG - Tuesday, November 13, 2018 7:35 AM

    muthukkumaran Kaliyamoorthy - Monday, November 12, 2018 10:24 PM

    VoldemarG - Monday, November 12, 2018 9:03 PM

    when running a loing SQL Statement with Actual Plan On it takes 2 hours.
    if run without Actual Exec Plan it takes 20 minutes.
    Is it realistic that Execution Plan made SUCH a big difference?

    It make a sight difference not some what you have, Can you post the code and plan.

    Well.. it is a query that within the cursor selects 50 000 times from the view that selects from the other view that selects from 5 other nested views...
    We are OK with the query running 20 minutes. I was still thinking that I can improve it by cutting another 10 minutes but its not critical. May be the query plan is so huge that it really slows down the execution of this code so noticeably. I have attached the code but have no idea how to get rid of this cursor...

    It's probably generating an execution plan for each of the 50,000 queries.

  • Jonathan AC Roberts - Tuesday, November 13, 2018 7:41 AM

    VoldemarG - Tuesday, November 13, 2018 7:35 AM

    muthukkumaran Kaliyamoorthy - Monday, November 12, 2018 10:24 PM

    VoldemarG - Monday, November 12, 2018 9:03 PM

    when running a loing SQL Statement with Actual Plan On it takes 2 hours.
    if run without Actual Exec Plan it takes 20 minutes.
    Is it realistic that Execution Plan made SUCH a big difference?

    It make a sight difference not some what you have, Can you post the code and plan.

    Well.. it is a query that within the cursor selects 50 000 times from the view that selects from the other view that selects from 5 other nested views...
    We are OK with the query running 20 minutes. I was still thinking that I can improve it by cutting another 10 minutes but its not critical. May be the query plan is so huge that it really slows down the execution of this code so noticeably. I have attached the code but have no idea how to get rid of this cursor...

    It's probably generating an execution plan for each of the 50,000 queries.

    Yes, this. It's rendering 50,000 execution plans and displaying them which is taking the time.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • is there any way to save the execution plan in the background (not on SSMS GUI) while the query is running, and then open the plan for review at a later time ?

    Likes to play Chess

  • VoldemarG - Tuesday, November 13, 2018 11:30 AM

    is there any way to save the execution plan in the background (not on SSMS GUI) while the query is running, and then open the plan for review at a later time ?

    Do you need to go through all 50,000 rows when performance testing?

  • I looked through the code and it looks to me that you could eliminate the cursor if you reworked everything inside the cursor.
    Also noticed that you made sure that in the event of a deadlock this set of queries will always win and that you are using read uncommitted transactions which means you could have issues with your data.
    I would take a shot at reworking the code but I would need the DDL for the tables and functions used, sample data that at least provided about 10 rows of data for each school, as well as data for the calendar type tables, and of course there would need to be expected results based on the sample data.  I would also need to do the work during the evenings as this wouldn't be a simple rewrite.

Viewing 9 posts - 1 through 8 (of 8 total)

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