Home Forums SQL Server 2012 SQL 2012 - General SQL Query - Actual performance duration for every execution RE: SQL Query - Actual performance duration for every execution

  • mrinal.technology (4/16/2013)


    Hi,

    I have a SQL query with couple of nested queries (query at the bottom for the reference), now the very first time I execute the query on a SQL Server instance, it takes around 50-60 seconds to execute, but there on for every consecutive execution, it barely takes 1 second and I am baffled, because I want it to take its original time for me to do anything about reduction of its original execution time. I want to try various tuning and query modification aspects.

    I have tried clearing all caches using the commands listed underneath, but they does not help in getting the original execution time.

    We are using "SQL Server 2012 Enterprise Edition"

    ...

    Can you please post the actual execution plan (as attachments) for a slow run and a fast run? If you're not sure how to do this, there are instructions in the first link in my sig.

    Please detail how you will get a new "very first time" now that it's been run.

    The query is unnecessarily convoluted and has potentially serious design flaws. Unless this is a deliberate attempt to generate a poor plan, I'd consider rewriting it as a higher priority than performance concerns.

    “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