**How do databases get from SQL query to result? How do they do it *quickly*?**
In this talk, we'll discuss how to represent queries as trees, look at some basics of query optimization and look into the Postgres query planner specifically. With some examples, we'll see how it uses statistics, estimates costs and ultimately decides on an execution plan. We'll open the hood, read some query plans, see what can go wrong and talk about approaches for helping the planner out.