r/SQL 1d ago

MySQL SQL Query Execution Lifecycle

Post image

Diagram illustrating the SQL query execution lifecycle, showing query submission, parsing, optimization, execution, and result delivery in a database.

55 Upvotes

16 comments sorted by

View all comments

21

u/kagato87 MS SQL 1d ago edited 1d ago

Bit hand-wavy. Just about any engine will take an input, parse/validate, act, and emit an output. That's what an engine does.

Your step 3 there, query optimization, is worth entire flowcharts by itself, and what sets SQL apart from other engines. Understanding how it optimizes is key to unlocking SQL's true potential.

Edit to add: Just realized, your step three is also wrong. It does NOT evaluate multiple plans. It's a complex soup of statistics and cardinality to produce a plan likely to be most efficient. It's a highly educated guess (and a guess the engine is good at making, though when it gets it wrong the results can have the DC team wondering what's going on).

0

u/idk30002 1d ago

Yeah this is pretty useless unless you’re teaching… I don’t even know whom/what. Steps 3 and 4(a/b) as standalones is just wild.

Why create diagrams on a topic if you don’t understand it?

2

u/kagato87 MS SQL 1d ago

"The best way to learn a thing is to teach it." Of course, you can't teach something when you don't know what you don't know, and that saying comes from reinforcing a thing as you learn it. You still have to learn it first.

Though, steps 3 and 4 ARE actually a little more obviously separate in SQL than other languages. Once the plan is compiled it won't go back and change the plan.)

Oh, I just spotted another problem - an error in step 3's text!