Order of Execution

  • Nice. Thanks for the question kranthi1.aprdc!

  • Dalton Moore (7/24/2012)


    At least I was not the only one who noticed the first and third option were the same...

    I didn't bother reading the first or third as they don't begin with From.

    +1

    Cheers,

    Steve

  • Thanks for easy back-to-basics question!


    Sujeet Singh

  • Thanks for the question - cheers

    +1 on this being especially easy given the answers to choose from!

  • Thomas Abraham (7/24/2012)


    Thanks kranthi1.aprdc for the question. I see you are relatively new to the site. So good to see you jumping in with a QotD contribution. As others have suggested, this one might have been a bit too easy, with only one answer that started with "FROM". But, you're pointed in the right direction.

    Agreed. Great topic, and a very helpful area for study.

    Rob Schripsema
    Propack, Inc.

  • sreepathi1987 (7/24/2012)


    Simple question.....

    Is any answer verification doing before posting the questions ?

    not really...

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Nice question, thanks.

  • Jamsheer (7/23/2012)


    Thanks for the easy point.. I think the first and last options given are same..

    They were the same. Made it a bit easier 😉

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Easy one!

  • Good one should have included DISTINCT to make it more confusing.

  • Good straightforward question.

    But in the explanation: is that really the parsing order, or are you assuming that's the parsing order because it's the execution order? I don't think I've seen any documentation on MS's parsing order for T-SQL. It does seem a fairly reasonable parsing order though.

    Tom

  • SQLRNNR (7/24/2012)


    Jamsheer (7/23/2012)


    Thanks for the easy point.. I think the first and last options given are same..

    They were the same. Made it a bit easier 😉

    I didn't read beyond "select" in either of them, because I knew they were incorrect as soon as I saw select was first.

    Tom

  • L' Eomot Inversé (7/27/2012)


    Good straightforward question.

    But in the explanation: is that really the parsing order, or are you assuming that's the parsing order because it's the execution order? I don't think I've seen any documentation on MS's parsing order for T-SQL. It does seem a fairly reasonable parsing order though.

    Yes I think you're right. It is logically parsed that way. Doesn't the optimizer rearrange it to produce the most efficient plan for retrieving the data? So looking at an execution plan you can see where it will sometimes think it more efficient to group by first then filter on the Where Clause or it may filter on one expression in the where clause and then later hit another.

    That's probably why they can't list an execution order because the optimizer determines the parsing order by costs and statistics (could be out of date).

    "There is nothing so useless as doing efficiently that which should not be done at all." - Peter Drucker

  • charles.byrne (8/8/2012)


    L' Eomot Inversé (7/27/2012)


    Good straightforward question.

    But in the explanation: is that really the parsing order, or are you assuming that's the parsing order because it's the execution order? I don't think I've seen any documentation on MS's parsing order for T-SQL. It does seem a fairly reasonable parsing order though.

    Yes I think you're right. It is logically parsed that way.

    No, that is not true. Parsing (processing the string of characters into internnal symbols to represent the actual query) is not documented, but I don't think it's even possible to write a parser that doesn't operate either left-to-right or right-to-left.

    It's also not the actual order of execution since, as you mention, the optimizer is free to choose any execution plan that returns the correct results.

    The order of execution documented in Books Online is usually referred to as the "logical order of execution". It is what defines the correct results of the query. Basically, the result of any query can be described based on this order of execution. If you always follow this order, you will always get the correct results (but probably not always very fast). Any change made by the optimizer must guarantee that the results are still AS IF this order has been followed.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Very easy question!

Viewing 15 posts - 16 through 29 (of 29 total)

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