4 ms·
A database query planner is an optimizing compiler. It's also a major field of research, and in many ways, much more sophisticated than other kinds of optimizin
by jeffdavis 14y ago
A database query planner is an optimizing compiler. It's also a major field of research, and in many ways, much more sophisticated than other kinds of optimizing compilers.
In particular, it doesn't just optimize your algorithm, it chooses better algorithms for you.
It does this by collecting statistics about the data (and keeping them up to date), and using those statistics to estimate the inputs to each operator in a candidate plan (a combination of algorithms that answers the query), and then estimate costs, and choose the candidate plan with the lowest cost.
(The above explanation is simplified and not entirely accurate. It discards most candidate plans before they even really become a plan. And "candidate plan" is not really the right terminology, but I thought it was more descriptive at a high level.)