Introduction to the PostgreSQL Source Code
Startup
-
main: `postmaster' vs. `postgres'
-
postmaster -> PostmasterMain()
-
Parse command line options
-
ServerLoop()
-
BackendStartup()
-
DoBackend() ->authentication ->postgres
-
postgres -> PostgresMain()
-
BaseInit()
-
PostgresInit()
-
Begin FE/BE query level interaction
-
Look for `Q' - Query
-
If received, pg_exec_query_string()
-
pg_parse_query() - build list of node trees representing
query
-
pg_analyze_and_rewrite() - parse to interal data respresentation
and rewrite if necessary
-
if node is CMD_UTILITY ->ProcessUtility()
-
else pg_plan_query()
-
planner-> subquery_planner()
-
optimise: any queries in join tree; preprocess join tree
(constants, etc); preprocess target list; build top level grouping/aggregate
plans
-
final planning: SS_finalize_plan()
-
ProcessQuery() -> ExecutorRun() -> ExecutePlan() -> ExecProcNode()
-
Determine plan type: seqscan, index scan, cursor...
-
Read out a slot (result tuple)
-
Determine query type: CMD_INSERT, CMD_DELETE, etc and update
tuple
-
continue back end looping