Steps of a Query (simplified)
- Client (aka application) connects to the backend (aka database server) [cached connections]
- Client transmits a SQL statement to the backend
- Parser attempts to read the statement. If errors are found, it stops
and bounces them to the client
- If no errors were found, a parse tree is created. This is an
internal structure that breaks apart your query into a logical, simplified
form. Similar to the "adjective - noun - verb" charts from school. Actually
looks like a tree or a nested set
- The rewrite system changes the parse tree as needed if there are
any rules or views involved in the query
- Now that the system knows exactly what to fetch, it needs to figure out
how to get that information back to the client, in as timely a
manner as possible. This is the job of the planner/optimizer
- The planner tries out every possible way of "running through" the parse tree.
Some simple queries only have one possible path through the parse tree,
but most will have many. Each plan is assigned a cost, and is the job
of the optimizer to pick the best one. [scanning and joining]
- TSP and GEQO
- See src/backend/optimizer/geqo/geqo_main.c (a "Genetic Algorithm query optimization")
- The winning plan is handed to the executor, which recursively descends the
tree, then returns the information from the top node of the tree to the
client/application
Previous: Faster
[Table of Contents]
Next: EXPLAIN explained