predictive query plan

  • Dear Friends,

    Please advise if there is a way to get a query plan for a query without running the query.Thank you in advance.

    Thanks and best regards

  • Estimated execution plans through SSMS, EXPLAIN, and SET SHOWPLAN_XML are available for dedicated SQL pools (formerly SQL DW) and dedicated SQL pools in Azure Synapse Analytics.

    Display the estimated execution plan for a query:

    1.     On the toolbar, select Database Engine Query. You can also open an existing query and display the estimated execution plan by selecting the Open File toolbar button and locating the existing query.

    2.     Enter the query for which you would like to display the estimated execution plan.

    3.     On the Query menu, select Display Estimated Execution Plan or select the Display Estimated Execution Plan toolbar button. The estimated execution plan is displayed on the Execution Plan tab in the results pane.

    Capture

    To view additional information, pause the mouse over the logical and physical operator icons and view the description and properties of the operator in the displayed ToolTip. Alternatively, you can view operator properties in the Properties window. If Properties is not visible, right-click an operator and select Properties. Select an operator to view its properties.

    4.     To alter the display of the execution plan, right-click the execution plan and select Zoom In, Zoom Out, Custom Zoom, or Zoom to Fit. Zoom In and Zoom Out allow you to magnify or reduce the execution plan by fixed amounts. Custom Zoom allows you to define your own display magnification, such as zooming at 80 percent. Zoom to Fit magnifies the execution plan to fit the result pane. Alternatively, use a combination of the CTRL key and your mouse wheel to activate dynamic zoom.

    5.     To navigate the display of the execution plan, use the vertical and horizontal scroll bars, or select and hold on any blank area of the execution plan, and drag your mouse. Alternatively, select and hold the plus (+) sign in the right lower corner of the execution plan window, to display a miniature map of the entire execution plan.

    Alternatively, use SET SHOWPLAN_XML to return execution plan information for each statement without executing it. If used in SQL Server Management Studio, the Results tab will have a link to open the execution plan in graphical format.

     

  • Also Please refer to  https://learn.microsoft.com/en-us/sql/relational-databases/showplan-logical-and-physical-operators-reference?view=sql-server-ver16

  • @Sridevi Kakolu...

    First, welcome aboard!

    Just to ask the question (and no argument from me one way or the other), did you actually construct all of your first reply or did you get some help from an AI or another source?  If it's all you, how long did it take to construct that answer?

    • This reply was modified 1 year, 8 months ago by  Jeff Moden. Reason: Change the wording a bit and add a secondary question

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Ah... never mind... I found the source.

    https://learn.microsoft.com/en-us/sql/relational-databases/performance/display-the-estimated-execution-plan

    Consider telling the OP the search you did to find this documentation so that they may help themselves in the future.  I believe it's important for people to learn how to find such things (as you have done) in the Microsoft documentation because they can get an answer more quickly than posting a question and waiting.

    And, posting the search you did may help others in the future, as well.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • @ Jeff Moden, Thank you so much. I am excited to start involve in these forum discussions. I did check this in Microsoft help documentation and provided the reference url for the same. I experienced this kind of situations when I was working for sharepoint rest api integrations, most of the times when I faced issues with the query strings, my colleague who expert in Sharepoint helped me finding the microsoft sharepoint help documentation. I feel for most of our day to day issues we can try get help in product documentations. Some scenarios we might face issues when we want to build beyond out of the box functionalities and customized approaches then we can brainstorm with experts to get ideas differently. FYI, I did not start use ChatGPT yet, I still go with research on product specific documentations and forums discussions.

  • Like I said, glad to "meet" you.

    The reference you provided is very helpful but it doesn't tell the OP how to find content like you did for the first thing you posted.  That would be might helpful it you could tell folks how you found that documentation.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • @Sridevi kakolu,

    Thanks for the reply and the referenced material . I was worked with this option for many PTO tasks, but what I am looking for is , a query based or script based solution for the same .. I know it sound a bit superficial but great if possible? thanks .

  • Arsh wrote:

    @Sridevi kakolu,

    Thanks for the reply and the referenced material . I was worked with this option for many PTO tasks, but what I am looking for is , a query based or script based solution for the same .. I know it sound a bit superficial but great if possible? thanks .

    Kind of and that "hint" has already been given.  Lookup SET SHOWPLAN_XML and read the details.  You have to call the code but it won't actually run the code.

    https://learn.microsoft.com/en-us/sql/t-sql/statements/set-showplan-xml-transact-sql

    Also be aware that if certain things are present, like a Temp Table that needs to be populated, it may not be able to produce a plan.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • In addition to everything else already explained, you can go to the memory on the system in question and retrieve the execution plan from the Dynamic Management Views. This blog post shows just one example. If you have Query Store enabled on the database in question, you can also get the plan from there. All this, without running the query... a second time. It has have been executed, but you don't have to be the one to do the execution.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

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

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