SQL reaches the database
An application sends a SQL query over its database connection. The server receives a description of the result the application wants.
The parser, planner, and executor behind a SQL query.
An application sends a SQL query over its database connection. The server receives a description of the result the application wants.
PostgreSQL checks syntax and transforms the query into a tree. Names and expressions gain meaning through the database’s catalog.
The rewrite stage applies stored rules. A reference to a view can become a query against the base tables defined by that view.
The planner considers possible access paths and estimates their costs. It selects an execution plan, which might use an index or scan a table.
The executor follows the plan, fetching rows and applying operations such as joins, filters, and sorts. The resulting rows return to the application.
Keyboard: ←→
The PostgreSQL query pipeline, simplified. Plan choices depend on statistics, indexes, configuration, and the actual query.