How does the optimizer choose the JOIN order, and why do outer joins restrict it?
A report joins three large tables containing customers, orders, and order items. A developer wants to rearrange the tables in FROM because they're convinced the database always reads the first table listed before the others. Explain how PostgreSQL 16, MySQL 8.4, and ClickHouse 24.10 actually choose join order. What makes an execution plan expensive? Why can reordering INNER JOIN operations preserve the result while making the same changes to LEFT JOIN operations can change it? What would you check first if the query were running slowly?
ExplainJOIN and row countsSeniorData EngineerBackendAnalyst