Hacking the Query Planner, Again - Richard Guo: PGCon 2020
Channel: PGCon
Date: 2020-12-12

From https://www.pgcon.org/events/pgcon_2020/schedule/session/39-hacking-the-query-planner-again/

This talk will focus on how the planner works from a developer’s view and elaborate on the process of converting a query tree to a plan tree in details.

We can divide the planning process into 4 phases: preprocessing, scan/join planning, post scan/join planning and postprocessing. In this talk, I will explain what stuff is performed in each phase and what is the motivation to perform that. Topics will include: transforming ANY/EXISTS SubLinks into joins, flattening sub-selects, preprocessing expressions, reducing outer joins to inner joins, distributing quals to rels, collecting join ordering restrictions, removing useless joins, join searching process, upper planner path-ification, cost estimation, etc.

Tom Lane's 2011 talk "Hacking the Query Planner” talked about the overview of query planner. In this talk, I will cover the internals of query planner with more details and in a way more close to planner codes. I hope this will be helpful in understanding the internals of PostgreSQL's planner and in hacking the planner codes to improve it.