The optimizer evaluates different access strategies, estimates their costs using catalog statistics, and chooses the least expensive plan. This happens after parsing (A) and validation (B), and before execution (D).