1The Query Optimizer
When you send a query, the DB's 'Query Optimizer' analyzes it. It looks at table sizes and indexes, and generates dozens of potential 'Execution Plans' to fetch the data. It calculates the cost of each plan, picks the cheapest/fastest one, and executes it. This all happens in milliseconds.
