@@ -8,104 +8,101 @@ <H1 ALIGN=CENTER>
8
8
</ H1 >
9
9
< H2 ALIGN =CENTER >
10
10
by Bruce Momjian
11
- </ H2 ALIGN=CENTER >
11
+ </ H2 >
12
12
< P >
13
- Queries come into the backend via data packets coming in through TCP/IP
14
- and Unix Domain sockets. They are loaded into a string, and passed to
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
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-type- specific
21
+ identify the query type, and load the proper query-specific
22
22
structure, like
23
23
< A HREF ="../../include/nodes/parsenodes.h "> CreateStmt or SelectStmt.</ A >
24
24
< P >
25
25
The query is then identified as a < I > Utility</ I > function or a more
26
- complex query. < I > Utility</ I > queries are processed by a
27
- query-type- specific function in < A HREF ="../../backend/commands ">
28
- commands.</ A > Complex queries , like < I > SELECT, UPDATE,</ I > and
29
- < I > DELETE</ I > require much more handling.
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 < B > SELECT, UPDATE,</ B > and
29
+ < B > DELETE</ B > requires much more handling.
30
30
< P >
31
- The parser takes the complex queries , and creates a
31
+ The parser takes a complex query , and creates a
32
32
< A HREF ="../../include/nodes/parsenodes.h "> Query</ A > structure that
33
33
contains all the elements used by complex queries. Query.qual holds the
34
- WHERE clause qualification, which is filled in by
34
+ < B > WHERE</ B > clause qualification, which is filled in by
35
35
< A HREF ="../../backend/parser/parse_clause.c "> transformWhereClause().</ A >
36
36
Each table referenced in the query is represented by a < A
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
40
makeRangeTable().</ A > Query.rtable holds the queries range table.
41
41
< P >
42
- Certain queries, like SELECT, return columns of data. Other queries,
43
- like INSERT and UPDATE, specify the columns modified by the query.
44
- These column references are converted to < A
45
- HREF ="../../include/nodes/primnodes.h "> Resdom</ A > entries, which are
42
+ Certain queries, like < B > SELECT,</ B > return columns of data. Other
43
+ queries, like < B > INSERT</ B > and < B > UPDATE,</ B > specify the columns
44
+ modified by the query. These column references are converted to < A
45
+ HREF ="../../include/nodes/primnodes.h "> Resdom</ A > entries, which are
46
46
linked together to make up the < I > target list</ I > of the query. The
47
47
target list is stored in Query.targetList, which is generated by
48
48
< A HREF ="../../backend/parser/parse_target.c "> transformTargetList().</ A >
49
49
< P >
50
- Other query elements, like aggregates(SUM()), GROUP BY, ORDER BY are
51
- also stored in their own Query fields.
50
+ Other query elements, like aggregates(< B > SUM()</ B > ), < B > GROUP BY,</ B >
51
+ < B > ORDER BY </ B > are also stored in their own Query fields.
52
52
< P >
53
- The next step is for the Query to be modified by any VIEWS or RULES that
54
- may apply to the query. This is performed by the < A
53
+ The next step is for the Query to be modified by any < B > VIEWS</ B > or
54
+ < B > RULES </ B > that may apply to the query. This is performed by the < A
55
55
HREF ="../../backend/rewrite "> rewrite</ A > system.
56
56
< P >
57
57
The < A HREF ="../../backend/optimizer "> optimizer</ A > takes the Query
58
- structure, and generates an optimal
59
- < A HREF ="../..//include/nodes/plannodes.h "> Plan</ A > containing the
60
- primitive operations to be performed by the executor to execute the
61
- query. The < A HREF ="../../backend/optimizer/path "> path</ A > module
62
- determines the best table join order and join type of each table in the
63
- RangeTable, using Query.qual(WHERE clause) to consider optimal index
64
- usage.
58
+ structure and generates an optimal < A
59
+ HREF ="../..//include/nodes/plannodes.h "> Plan,</ A > which contains the
60
+ operations to be performed to execute the query. The < A
61
+ HREF ="../../backend/optimizer/path "> path</ A > module determines the best
62
+ table join order and join type of each table in the RangeTable, using
63
+ Query.qual(< B > WHERE</ B > clause) to consider optimal index usage.
65
64
< P >
66
65
The Plan is then passed to the < A
67
66
HREF ="../../backend/executor "> executor</ A > for execution, and the result
68
- is returned to the client.
67
+ returned to the client.
69
68
< P >
70
- There are many other modules that support this basic functionality.
69
+ There are many other modules that support this basic functionality.
71
70
They can be accessed by clicking on the flowchart.
72
71
< P >
73
72
Another area of interest is the shared memory area, containing
74
73
table data/index blocks, locks, and backend information:
75
74
< UL >
76
- < LI > ShmemIndex - contains an index of all other shared memory
77
- structures, allowing quick lookup of other structure locations in shared
78
- memory
75
+ < LI > ShmemIndex - lookup of shared memory addresses using structure names
79
76
< LI > < A HREF ="../../include/storage/buf_internals.h "> Buffer
80
- Descriptors</ A > - control header for shared memory buffer block
81
-
82
- < LI > < A HREF =" ../../include/storage/buf_internals.h " > Buffer Blocks </ A >
83
- - block of table/index data shared by all backends
84
- < LI > Shared Buf Lookup Table - lookup to see if a requested buffer
85
- is already in the shared memory area
86
- < LI > < A HREF ="../../include/storage/lock.h "> LockTable</ A >
87
- - lock table structure, specifiying table, lock types, and
88
- backends holding or waiting on lock
89
- < LI > LockTable (lock hash) - lookup of LockTable structures using
90
- table name
77
+ Descriptors</ A > - control header for buffer cache block
78
+ < LI > < A HREF =" ../../include/storage/buf_internals.h " > Buffer Blocks </ A > -
79
+ data/index buffer cache block
80
+ < LI > Shared Buf Lookup Table - lookup of buffer cache block address using
81
+ table name and block number( < A HREF =" ../../include/storage/buf_internals.h " >
82
+ BufferTag </ A > )
83
+ < LI > < A HREF ="../../include/storage/lock.h "> LockTable (ctl) </ A > - lock table
84
+ structure, specifiying table, lock types, and backends holding or
85
+ waiting on lock
86
+ < LI > LockTable (lock hash) - lookup of LockTable structures using relation
87
+ and database object ids
91
88
< LI > LockTable (xid hash) - lookup of LockTable structures using
92
89
transaction id
93
90
< LI > < A HREF ="../../include/storage/proc.h "> Proc Header</ A > - information
94
91
about each backend, including locks held/waiting, indexed by process id
95
92
</ UL >
96
93
Each data structure is created by calling < A
97
- HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitStruct(),</ A > and
98
- the lookup hashes are created by
94
+ HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitStruct(),</ A > and
95
+ the lookups are created by
99
96
< A HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitHash().</ A >
100
97
< HR >
101
98
< CENTER >
102
99
< EM > < BIG >
103
- Click on an item to see more detail or click
104
- < A HREF ="backend_dirs.html "> here </ a > to see the full index.
105
- </ EM > </ BIG >
100
+ Click on an item to see more detail or
101
+ < A HREF ="backend_dirs.html "> click </ A > to see the full index.
102
+ </ BIG > </ EM >
106
103
< BR >
107
104
< BR >
108
- < IMG src ="flow.jpg " usemap ="#flowmap ">
105
+ < IMG src ="flow.jpg " usemap ="#flowmap " alt =" flowchart " >
109
106
</ CENTER >
110
107
< MAP name ="flowmap ">
111
108
< AREA COORDS ="290,10,450,50 " HREF ="backend_dirs.html#main ">
0 commit comments