Query execution plan

  • Hi Guys,

    Is it possible to check query execution plan of a store procedure from create script (before creating it)?

    Basically the developers want to know how a newly developed procedure will perform in production environment. Now, I don't want to create it in production for just checking the execution plan. However they've provided SQL script for the procedure. Now wondering is there any way to look at the execution plan for this procedure from the script provided?

    Thanks.

  • I don't see the problem: create it, grab the execution plan, then drop it.

    If it overwrites an existing procedure, create it with a different name.

    -- Gianluca Sartori

  • Thanks for your reply Gianluca.

    Yes, that's one option. However we generally have to go through change request process to make any changes and every changes are audited at the database level as well. I guess if there's no way to check that, I'll have to go through that bureaucratic process.

    Thanks

  • You could also create a temporary stored procedure (just prepend # to the proc name).

    -- Gianluca Sartori

  • Okay, thanks. So bottom line is that procedure has to be created to look at the execution plan, right?

  • That's how it works

    -- Gianluca Sartori

  • Understood, thanks once again for your time Gianluca.

  • Any time

    -- Gianluca Sartori

  • salamlemon (6/17/2015)


    Okay, thanks. So bottom line is that procedure has to be created to look at the execution plan, right?

    Yes, but no. If there are no parameters, you can capture the estimated plan(s) by selecting everything within the bounds of the procedure and clicking on the estimated plan button. If there are parameters, you have to change them to DECLARE then set values, otherwise the same. Technically you're not adding a new stored procedure nor running any statements which could change the database state.

    If you want to capture the actual execution plan of the stored procedure and especially if the code contains INSERT/UPDATE/DELETE statements, then I find it easiest to create it then run it in a transaction like this:

    BEGIN TRAN

    run stored procedure

    ROLLBACK TRAN

    Something between these two should work for you.

    “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

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

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