1.1 Where Does a Query Go?
Source: Dev.to
PostgreSQL Internals – Chapter 1: Query Processing
When a client sends a statement such as
SELECT * FROM users WHERE id = 1;
the SQL travels through a five‑stage pipeline inside the PostgreSQL backend before a result row is returned.
1. Backend entry and dispatch
The backend receives the client message and decides which processing path to follow.
2. Parser and Analyzer
The SQL text is parsed, and the system catalog is consulted to give the query meaning.
3. Rewriter
The RULE system expands views, injects row‑level‑security (RLS) policies, and otherwise transforms the query tree.
4. Planner
Using a cost model, PostgreSQL explores possible execution paths and selects the most efficient one.
5. Executor
The chosen plan is walked, tuples are pulled up, and the results are sent back to the client.
Chapter 1.1 – Entry Point
Chapter 1.1 focuses on the first stage of the pipeline—the backend’s entry point. It is divided into three sections:
1.1.1 Life of a Query
A single diagram that compresses all five stages, providing a map for the rest of the book.
1.1.2 Simple vs Extended
Explores the semantic differences between the Simple Query protocol and the Extended Query protocol.
1.1.3 Optimizable vs Utility
Shows how optimizable statements (e.g., SELECT, INSERT, UPDATE, DELETE) follow a different path from utility commands (e.g., CREATE, VACUUM).
After completing this chapter, you should understand how the backend’s main loop receives a client message and dispatches it to the appropriate function.