Query Plan Execution Order

  • Sergiy (1/15/2012)


    Both fuel counter and row counter are reset before the counted substance is being delivered.

    Just proves the analogy is correct.

    So the fuel counter executes first, cool. The analogy isn't a false analogy; just not a useful one (in my opinion).

    If a fact does not fit your theory ditch the fact.

    It's not a theory, it's published fact.

  • Sergiy (1/15/2012)


    How happy are those people about this one: Cursor loop executes before the first row of the cursor is fetched? Or Main routine executes before any of its subroutines?

    You would have to ask them, but it does seem obvious that subroutines are called by a parent routine, and that cursors are declared and initialized before any data is fetched through them.

  • SQL Kiwi (1/15/2012)


    So the fuel counter executes first, cool. [/qoute]

    Which means - Fuel counting executes before fuel is pumped.

    Did you try it on real life people?

    πŸ™‚

    It's not a theory, it's published fact.

    "Published" does not mean "fact".

    The "fact" about the Sun circling around the Earth was published so many times during so many centuries by such big authorities that people got executed for defying that "fact".

    I hope not to be executed for defying the "fact" published by big MVP's.

    πŸ™‚

    _____________
    Code for TallyGenerator

  • Fun part:

    Question:

    Which query plan operator executes first?

    Correct answer:

    The Stream Aggregate

    My question:

    Sorry, the Stream Aggregate executes what?

    _____________
    Code for TallyGenerator

  • Hi Paul and Sergiy,

    Can you please drop this? You are now both reiterating the same point again and again.

    Sergiy has made his point that he disagrees with the answer (and even with the question, it seems). We all understand that.

    It's also pretty obvious by now that Sergiy is not able to convince Paul (or any others who responded, including me) to see things his way. And that all who responded (mainly Paul at this time) are equally unable to convince Sergiy to see things our way.

    I think continuing to argue is just a waste of everyone's time and energy - so I propose that we all just agree to disagree on this one, and move on.

    Agreed?


    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/

  • Sergiy (1/15/2012)


    Which means - Fuel counting executes before fuel is pumped.

    The part that resets the counter does, yes. Of course, the total amount of fuel pumped is only shown once dispensing of fuel is complete. The analogy is not perfect because the mechanics of query plan execution and fuel dispensing are not that close. The fuel system has a direct feedback to shut off fuel delivery when the operator releases the nozzle grip, or when a pre-set volume or cost of fuel has been delivered. Fuel delivery would also stop, I guess, if the underground tank ran dry, but that is not the usual situation.

    The analogy might work a little better in a simple SELECT COUNT(*) FROM Table plan, or perhaps one with a subquery with a TOP operator, but that is stretching things a bit. It's hard to see where the JOIN appears in fuel delivery for example. In any case, it all comes back to how the reader interprets 'executes'. Your view differs from the majority, which doesn't make it wrong, but many of your statements about other things have been. Your recent posts suggest that some of the learning points from this QotD have stated to sink in, which is the whole point.

  • Sergiy (1/15/2012)


    Fun part: Question: Which query plan operator executes first? Correct answer: The Stream Aggregate

    Thank goodness!

    My question: Sorry, the Stream Aggregate executes what?

    First! πŸ˜€

  • Hugo Kornelis (1/16/2012)


    Hi Paul and Sergiy,

    Can you please drop this? You are now both reiterating the same point again and again.

    Sergiy has made his point that he disagrees with the answer (and even with the question, it seems). We all understand that.

    It's also pretty obvious by now that Sergiy is not able to convince Paul (or any others who responded, including me) to see things his way. And that all who responded (mainly Paul at this time) are equally unable to convince Sergiy to see things our way.

    I think continuing to argue is just a waste of everyone's time and energy - so I propose that we all just agree to disagree on this one, and move on.

    Agreed?

    Hi Hugo,

    If Sergiy were simply trolling I would agree; but for me, the discussion still has value: Sergiy has picked up a few key concepts and learned that correlated seeks don't happen before the driving scan, for example. I fully don't expect him (or her) to ever fully accept that the question and answer are perfect (they're not!) but so long as even small progress is being made, I don't see it as a waste of my time.

  • Sergiy (1/12/2012)


    Hugo Kornelis (1/12/2012)


    I think the problem is lingual.

    "Is executed" can have two meanings.

    1. Present tense, passive form - the code is invoked. Can be compared to running "EXEC MyStoredProc" in SQL Server. As soon as you run that command, execution passes to the first statement of your stored procedure - your stored procedure "is executed".

    2. Present tense with perfect aspect - execution has finished. When the execution of your stored procedure has finished and control is returned to the caller, the stored procedure "is executed" (though I think most English speakers would use "has executed" here).

    Paul's intention, and my interpretation, is the first meaning: execution starts. And with that meaning, Stream Aggregate is the correct answer, This is the first operator that gets control, initializes itself, then passes control to (by calling) the next operator.

    Another way to explain this is to remember that operators do not "push" rows up to their parent operator; operators "pull" rows from their descendants. (Or, as Rob Farley worded it, "execution plans suck").

    I don't think it's lingual.

    An awful lot of bandwidth would have been saved if you'd just said "yes I agree, it's lingual"!

    πŸ˜‰

  • SQL Kiwi (1/15/2012)


    Sergiy (1/15/2012)


    How happy are those people about this one: Cursor loop executes before the first row of the cursor is fetched? Or Main routine executes before any of its subroutines?

    You would have to ask them, but it does seem obvious that subroutines are called by a parent routine, and that cursors are declared and initialized before any data is fetched through them.

    Actually, it is a real pain to use a cursor in such a way that the loop processing rows is entered before the first fetch is executed. I imagine that's what Sergiy is referring to as a "cursor loop", and that he's pointing out that the first fetch is executed before that loop is entered. But I can't see any connection at all between that and this QotD.

    Aynway, to answer Sergiy's happiness question (I probably shouldn't answer it, but as he's specifically asked I think I have a little license here): I'm happy because the QotD and it's answer are perfectly correct (well, nothings perfect - but as near as we get), but thoroughly unhappy because Sergiy seems to be trying to turn the discussion into a debate on the meaning of the verb "execute" which has been interpreted with total accuracy by Paul and can never (in the English I hear, speak, read, and write) be interpreted as meaning "finishes its execution" as S appears to want it to be, and bringing up completely irrelevant and pointless analogies. Perhaps he could start a new thread on the meaning of "execute" (which we could all ignore)? Maybe I'm being unfair, but I can't see any point to the continuing discussion.

    Tom

  • SQL Kiwi (1/16/2012)


    Sergiy (1/15/2012)


    Which means - Fuel counting executes before fuel is pumped.

    The part that resets the counter does, yes.

    Part of it. Exactly. But not the whole operation.

    Of course, the total amount of fuel pumped is only shown once dispensing of fuel is complete.

    Glad you have finally agreed!

    The analogy is not perfect because the mechanics of query plan execution and fuel dispensing are not that close. The fuel system has a direct feedback to shut off fuel delivery when the operator releases the nozzle grip

    You may hit "Stop" button any time. Pretty much the same thing.

    or when a pre-set volume or cost of fuel has been delivered.

    TOP operator does exactly that.

    Fuel delivery would also stop, I guess, if the underground tank ran dry

    If you run aggregation against all records then you'll stop only when there are no more records int the "undeground tank".

    It's hard to see where the JOIN appears in fuel delivery for example.

    It's more obvious for our American friends. They've got a single nozzle for all types of fuel.

    So their pump stations have a "JOIN dbo.FuelType" operator somewhere inside, between the tanks and the nozzle.

    In any case, it all comes back to how the reader interprets 'executes'. Your view differs from the majority,

    5 or 10 people are not the majority.

    Did you test "Fuel counting executes before fuel pumping" on other people?

    Try it and see what the real majority will agree with.

    _____________
    Code for TallyGenerator

  • Toreador (1/16/2012)


    An awful lot of bandwidth would have been saved if you'd just said "yes I agree, it's lingual"!

    πŸ˜‰

    Well, as long as we communicate here in some language, it has to be lingual.

    -Die not spare life!

    Life depends on where you put a comma.

    Semantics, nothing else.

    In another QoD with very similar meanin Paul asked "Which table is accessed first?"

    If it would be "scanned" or "read" then there would be a space for a similar argument.

    But "accessed" is exactly the word which describes what he had in mind.

    In this case "executes" was an obviously bad choice.

    Lack of answer on "executes what?" proves the point.

    _____________
    Code for TallyGenerator

  • L' Eomot InversΓ© (1/16/2012)


    Aynway, to answer Sergiy's happiness question (I probably shouldn't answer it, but as he's specifically asked I think I have a little license here): I'm happy because the QotD and it's answer are perfectly correct (well, nothings perfect - but as near as we get), but thoroughly unhappy because Sergiy seems to be trying to turn the discussion into a debate on the meaning of the verb "execute" which has been interpreted with total accuracy by Paul and can never (in the English I hear, speak, read, and write) be interpreted as meaning "finishes its execution" as S appears to want it to be, and bringing up completely irrelevant and pointless analogies. Perhaps he could start a new thread on the meaning of "execute" (which we could all ignore)? Maybe I'm being unfair, but I can't see any point to the continuing discussion.

    I now agree with you and Hugo. Time to move on, I think.

  • I see you've got the petrol station analogy.

    Time to wrap it up.

    πŸ™‚

    _____________
    Code for TallyGenerator

Viewing 14 posts - 91 through 103 (of 103 total)

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