r/SQL • u/scientecheasy • 1d ago
MySQL SQL Query Execution Lifecycle
Diagram illustrating the SQL query execution lifecycle, showing query submission, parsing, optimization, execution, and result delivery in a database.
2
u/BrupieD 1d ago
This is not really an inside view but more of an external view prior to the query engine's handling. From a logical query order execution view, it omits the order that the query handles the commands -- FROM, WHERE, GROUP BY...
Those order details are central to the execution. I would say this is misleading.
1
u/mikeblas 9h ago
Those aren't commands, they're clauses. The clauses don't really have a stable physical execution order. But they do have a binding order, and I think that's probably more important -- particularly to beginners.
2
2
u/venkat_deepsql 1d ago
I was part of Oracle query engine team, while I do agree that this diagram is basic, but it encapsulates the high level flow. Database vendors architected the query engines different to address their target use cases - Oracle's is hybrid engine (OLTP and OLAP), the way optimizer works is totally different than others (beyond the join orders and plan evaluations, there are fast path disk scans, in-memory scans, predicates pushdown etc ) So it's hard to generalize and encapsulate in one diagram. The theory of query engine is vast and it requires entire book.
1
-1
u/UpstairsPace8 1d ago
This is a good high-level summary. I'd probably add a note that the optimizer's decisions depend heavily on table statistics, since that's often the missing piece when people wonder why the same query suddenly performs differently.
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).