1
1
< HTML >
2
2
< HEAD >
3
- < TITLE > PostgreSQL Backend Flowchart </ TITLE >
3
+ < TITLE > How PostgreSQL Processes a Query </ TITLE >
4
4
</ HEAD >
5
5
< BODY BGCOLOR ="#FFFFFF " TEXT ="#000000 " LINK ="#FF0000 " VLINK ="#A00000 " ALINK ="#0000FF ">
6
6
< H1 ALIGN =CENTER >
7
- PostgreSQL Backend Flowchart
7
+ How PostgreSQL Processes a Query
8
8
</ H1 >
9
9
< H2 ALIGN =CENTER >
10
10
by Bruce Momjian
11
11
</ H2 >
12
12
< P >
13
- A query come into the backend via data packets coming in through TCP/IP
14
- and Unix Domain sockets. It is loaded into a string, and passed to
13
+ A query comes to the backend via data packets arriving through TCP/IP
14
+ or Unix Domain sockets. It is loaded into a string, and passed to
15
15
the
16
16
< A HREF ="../../backend/parser "> parser,</ A > where the lexical scanner,
17
17
< A HREF ="../../backend/parser/scan.l "> scan.l,</ A >
18
18
breaks the query up into tokens(words). The parser
19
19
uses
20
20
< A HREF ="../../backend/parser/gram.y "> gram.y</ A > and the tokens to
21
- identify the query type, and load the proper query-specific
22
- structure, like
23
- < A HREF ="../../include/nodes/parsenodes.h "> CreateStmt or SelectStmt.</ A >
21
+ identify the query type, and load the proper query-specific structure,
22
+ like < A HREF =" ../../include/nodes/parsenodes.h " > CreateStmt </ A > or < A
23
+ HREF ="../../include/nodes/parsenodes.h "> SelectStmt.</ A >
24
24
< P >
25
- The query is then identified as a < I > Utility</ I > function or a more
26
- complex query. A < I > Utility</ I > query is processed by a
27
- query-specific function in < A HREF ="../../backend/commands ">
28
- commands. </ A > A complex query, like < CODE > SELECT, UPDATE,</ CODE > and
25
+ The query is then identified as a < I > Utility</ I > query or a more complex
26
+ query. A < I > Utility</ I > query is processed by a query-specific function
27
+ in < A HREF ="../../backend/commands "> commands. </ A > A complex query, like
28
+ < CODE > SELECT, UPDATE,</ CODE > and
29
29
< CODE > DELETE</ CODE > requires much more handling.
30
30
< P >
31
31
The parser takes a complex query, and creates a
@@ -37,7 +37,7 @@ <H2 ALIGN=CENTER>
37
37
HREF ="../../include/nodes/parsenodes.h "> RangeTableEntry,</ A > and they
38
38
are linked together to form the < I > range table</ I > of the query, which is
39
39
generated by < A HREF ="../../backend/parser/parse_clause.c ">
40
- makeRangeTable().</ A > Query.rtable holds the queries range table.
40
+ makeRangeTable().</ A > Query.rtable holds the query's range table.
41
41
< P >
42
42
Certain queries, like < CODE > SELECT,</ CODE > return columns of data. Other
43
43
queries, like < CODE > INSERT</ CODE > and < CODE > UPDATE,</ CODE > specify the columns
@@ -48,7 +48,7 @@ <H2 ALIGN=CENTER>
48
48
< A HREF ="../../backend/parser/parse_target.c "> transformTargetList().</ A >
49
49
< P >
50
50
Other query elements, like aggregates(< CODE > SUM()</ CODE > ), < CODE > GROUP BY,</ CODE >
51
- < CODE > ORDER BY</ CODE > are also stored in their own Query fields.
51
+ and < CODE > ORDER BY</ CODE > are also stored in their own Query fields.
52
52
< P >
53
53
The next step is for the Query to be modified by any < CODE > VIEWS</ CODE > or
54
54
< CODE > RULES</ CODE > that may apply to the query. This is performed by the < A
@@ -69,21 +69,22 @@ <H2 ALIGN=CENTER>
69
69
There are many other modules that support this basic functionality.
70
70
They can be accessed by clicking on the flowchart.
71
71
< P >
72
- Another area of interest is the shared memory area, containing table
73
- data/index blocks, locks, backend information, and lookup tables for
74
- these structures:
72
+ Another area of interest is the shared memory area, which contains data
73
+ accessable to all backends. It has table recently used data/index
74
+ blocks, locks, backend information, and lookup tables for these
75
+ structures:
75
76
< UL >
76
77
< LI > ShmemIndex - lookup shared memory addresses using structure names
77
78
< LI > < A HREF ="../../include/storage/buf_internals.h "> Buffer
78
- Descriptors </ A > - control header for buffer cache block
79
- < LI > < A HREF ="../../include/storage/buf_internals.h "> Buffer Blocks </ A > -
79
+ Descriptor </ A > - control header for buffer cache block
80
+ < LI > < A HREF ="../../include/storage/buf_internals.h "> Buffer Block </ A > -
80
81
data/index buffer cache block
81
- < LI > Shared Buf Lookup Table - lookup of buffer cache block address using
82
+ < LI > Shared Buffer Lookup Table - lookup of buffer cache block addresses using
82
83
table name and block number(< A HREF ="../../include/storage/buf_internals.h ">
83
84
BufferTag</ A > )
84
- < LI > MultiLevelLockTable (ctl) - < A
85
- HREF =" ../../include/storage/lock.h " > LOCKCTL </ A > control structure for
86
- each locking method. Currently, only multi-level locking is used .
85
+ < LI > MultiLevelLockTable (ctl) - control structure for
86
+ each locking method. Currently, only multi-level locking is used( < A
87
+ HREF =" ../../include/storage/lock.h " > LOCKMETHODCTL </ A > ) .
87
88
< LI > MultiLevelLockTable (lock hash) - the < A
88
89
HREF ="../../include/storage/lock.h "> LOCK</ A > structure, looked up using
89
90
relation, database object ids(< A
@@ -105,7 +106,9 @@ <H2 ALIGN=CENTER>
105
106
HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitStruct(),</ A > and
106
107
the lookups are created by
107
108
< A HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitHash().</ A >
109
+ < P >
108
110
< HR >
111
+ < P >
109
112
< CENTER >
110
113
< EM > < BIG >
111
114
Click on an item to see more detail or
0 commit comments