It estimates the cost of candidate plans from statistics and picks the cheapest. EXPLAIN shows the chosen plan.