How often is the query plan optimal?
The basic promise of a query optimizer is that it picks the “optimal”
query plan. But there’s a catch - the plan selection relies on cost
estimates, calculated from selectivity estimates and cost of basic
resources (I/O, CPU, …). So the question is, how often do we
actually pick the “fastest” plan? And the truth is we actually
make mistakes quite often.Consider the following chart, with durations of a simple SELECT query
with a range condition. The condition is varied to match different
fraction...
Read more at vondra.me