Home > Database > Control flow of a query in PostgreSQL

Control flow of a query in PostgreSQL

January 27th, 2012

As of version 9.0.4

(source: src/backend/executor/README)

(1) CreateQueryDesc (tcop/pquery.c)
(2) ExecutorStart (executor/execMain.c)
    (2.1) CreateExecutorState (executor/execUtils.c)
    (2.2) ExecInitNode (executor/execProcnode.c)
        (2.2.1) CreateExprContext (executor/execUtils.c)
        (2.2.2) ExecInitExpr (executor/execQual.c)
(3) ExecutorRun (executor/execMain.c)
    (3.1) ExecProcNode (executor/execProcnode.c)
        (3.1.1) ExecEvalExpr (include/executor/executor.h)
        (3.1.2) ResetExprContext (include/executor/executor.h)
(4) ExecutorEnd (executor/execMain.c)
    (4.1) ExecEndNode (executor/execProcnode.c)
    (4.2) FreeExecutorState (executor/execUtils.c)
(5) FreeQueryDesc (tcop/pquery.c)

“CreateQueryDesc” is will be invoked through a series of calls following

exec_simple_query (tcop/postgres.c)
|->1. pg_analyze_and_rewrite (tcop/postgres.c)
|->2. pg_plan_queries (tcop/postgres.c)
|->3. PortalStart (tcop/pquery.c)
|-----> ...

“A portal is an abstraction which represents the execution state of a running or runnable query.” — “include/utils/portal.h”. In the comments of the header file, we can see the strategies used by different types of queries.

Mr. One Database

  1. No comments yet.
  1. No trackbacks yet.