@@ -43,37 +43,35 @@ <H2 ALIGN=CENTER>
43
43
44
44
< HR >
45
45
< P >
46
- A query comes to the backend via data packets arriving through TCP/IP
47
- or Unix Domain sockets. It is loaded into a string, and passed to
48
- the
46
+
47
+ A query comes to the backend via data packets arriving through TCP/IP or
48
+ Unix Domain sockets. It is loaded into a string, and passed to the
49
49
< A HREF ="../../backend/parser "> parser,</ A > where the lexical scanner,
50
- < A HREF ="../../backend/parser/scan.l "> scan.l,</ A >
51
- breaks the query up into tokens(words). The parser
52
- uses
53
- < A HREF ="../../backend/parser/gram.y "> gram.y</ A > and the tokens to
54
- identify the query type, and load the proper query-specific structure,
55
- like < A HREF ="../../include/nodes/parsenodes.h "> CreateStmt</ A > or < A
56
- HREF ="../../include/nodes/parsenodes.h "> SelectStmt.</ A >
57
- < P >
50
+ < A HREF ="../../backend/parser/scan.l "> scan.l,</ A > breaks the query up
51
+ into tokens(words). The parser uses < A
52
+ HREF ="../../backend/parser/gram.y "> gram.y</ A > and the tokens to identify
53
+ the query type, and load the proper query-specific structure, like < A
54
+ HREF ="../../include/nodes/parsenodes.h "> CreateStmt</ A > or < A
55
+ HREF ="../../include/nodes/parsenodes.h "> SelectStmt.</ A > < P >
56
+
58
57
59
58
The query is then identified as a < I > Utility</ I > query or a more complex
60
59
query. A < I > Utility</ I > query is processed by a query-specific function
61
60
in < A HREF ="../../backend/commands "> commands.</ A > A complex query, like
62
- < I > SELECT, UPDATE,</ I > and
63
- < I > DELETE</ I > requires much more handling.
64
- < P >
61
+ < I > SELECT, UPDATE,</ I > and < I > DELETE</ I > requires much more handling.< P >
62
+
65
63
66
64
The parser takes a complex query, and creates a
67
65
< A HREF ="../../include/nodes/parsenodes.h "> Query</ A > structure that
68
66
contains all the elements used by complex queries. Query.qual holds the
69
- < I > WHERE</ I > clause qualification, which is filled in by
70
- < A HREF ="../../backend/parser/parse_clause.c "> transformWhereClause().</ A >
67
+ < I > WHERE</ I > clause qualification, which is filled in by < A
68
+ HREF ="../../backend/parser/parse_clause.c "> transformWhereClause().</ A >
71
69
Each table referenced in the query is represented by a < A
72
70
HREF ="../../include/nodes/parsenodes.h "> RangeTableEntry,</ A > and they
73
- are linked together to form the < I > range table</ I > of the query, which is
74
- generated by < A HREF ="../../backend/parser/parse_clause.c ">
75
- makeRangeTable().</ A > Query.rtable holds the query's range table.
76
- < P >
71
+ are linked together to form the < I > range table</ I > of the query, which
72
+ is generated by < A HREF ="../../backend/parser/parse_clause.c ">
73
+ makeRangeTable().</ A > Query.rtable holds the query's range table.< P >
74
+
77
75
78
76
Certain queries, like < I > SELECT,</ I > return columns of data. Other
79
77
queries, like < I > INSERT</ I > and < I > UPDATE,</ I > specify the columns
@@ -82,64 +80,65 @@ <H2 ALIGN=CENTER>
82
80
placed in < A HREF ="../../include/nodes/parsenodes.h "> target list
83
81
entries,</ I > and linked together to make up the < I > target list</ I > of
84
82
the query. The target list is stored in Query.targetList, which is
85
- generated by
86
- < A HREF ="../../backend/parser/parse_target.c "> transformTargetList().</ A >
87
- < P >
83
+ generated by < A
84
+ HREF ="../../backend/parser/parse_target.c "> transformTargetList().</ A > < P >
85
+
88
86
89
87
Other query elements, like aggregates(< I > SUM()</ I > ), < I > GROUP BY,</ I >
90
- and < I > ORDER BY</ I > are also stored in their own Query fields.
91
- < P >
88
+ and < I > ORDER BY</ I > are also stored in their own Query fields.< P >
89
+
92
90
93
91
The next step is for the Query to be modified by any < I > VIEWS</ I > or
94
92
< I > RULES</ I > that may apply to the query. This is performed by the < A
95
- HREF ="../../backend/rewrite "> rewrite</ A > system.
96
- < P >
93
+ HREF ="../../backend/rewrite "> rewrite</ A > system.< P >
94
+
97
95
98
96
The < A HREF ="../../backend/optimizer "> optimizer</ A > takes the Query
99
97
structure and generates an optimal < A
100
98
HREF ="../..//include/nodes/plannodes.h "> Plan,</ A > which contains the
101
99
operations to be performed to execute the query. The < A
102
100
HREF ="../../backend/optimizer/path "> path</ A > module determines the best
103
101
table join order and join type of each table in the RangeTable, using
104
- Query.qual(< I > WHERE</ I > clause) to consider optimal index usage.
105
- < P >
102
+ Query.qual(< I > WHERE</ I > clause) to consider optimal index usage.< P >
106
103
107
104
108
105
The Plan is then passed to the < A
109
106
HREF ="../../backend/executor "> executor</ A > for execution, and the result
110
107
returned to the client. The Plan actually as set of nodes, arranged in
111
108
a tree structure with a top-level node, and various sub-nodes as
112
- children.
113
- < P >
109
+ children.< P >
114
110
115
- There are many other modules that support this basic functionality.
116
- They can be accessed by clicking on the flowchart.
117
- < P >
118
111
119
- < HR >
120
- < P >
112
+ There are many other modules that support this basic functionality. They
113
+ can be accessed by clicking on the flowchart.< P >
114
+
115
+
116
+ < HR > < P >
117
+
121
118
122
119
Another area of interest is the shared memory area, which contains data
123
120
accessable to all backends. It has table recently used data/index
124
121
blocks, locks, backend information, and lookup tables for these
125
122
structures:
123
+
126
124
< UL >
127
125
< LI > ShmemIndex - lookup shared memory addresses using structure names
128
126
< LI > < A HREF ="../../include/storage/buf_internals.h "> Buffer
129
127
Descriptor</ A > - control header for buffer cache block
130
128
< LI > < A HREF ="../../include/storage/buf_internals.h "> Buffer Block</ A > -
131
129
data/index buffer cache block
132
- < LI > Shared Buffer Lookup Table - lookup of buffer cache block addresses using
133
- table name and block number(< A HREF =" ../../include/storage/buf_internals.h " >
134
- BufferTag</ A > )
135
- < LI > MultiLevelLockTable (ctl) - control structure for
136
- each locking method. Currently, only multi-level locking is used(< A
130
+ < LI > Shared Buffer Lookup Table - lookup of buffer cache block addresses
131
+ using table name and block number(< A
132
+ HREF =" ../../include/storage/buf_internals.h " > BufferTag</ A > )
133
+ < LI > MultiLevelLockTable (ctl) - control structure for each locking
134
+ method. Currently, only multi-level locking is used(< A
137
135
HREF ="../../include/storage/lock.h "> LOCKMETHODCTL</ A > ).
138
136
< LI > MultiLevelLockTable (lock hash) - the < A
139
137
HREF ="../../include/storage/lock.h "> LOCK</ A > structure, looked up using
140
138
relation, database object ids(< A
141
- HREF ="../../include/storage/lock.h "> LOCKTAG)</ A > . The lock table structure contains the
142
- lock modes(read/write or shared/exclusive) and circular linked list of backends (< A
139
+ HREF ="../../include/storage/lock.h "> LOCKTAG)</ A > . The lock table
140
+ structure contains the lock modes(read/write or shared/exclusive) and
141
+ circular linked list of backends (< A
143
142
HREF ="../../include/storage/proc.h "> PROC</ A > structure pointers) waiting
144
143
on the lock.
145
144
< LI > MultiLevelLockTable (xid hash) - lookup of LOCK structure address
@@ -152,11 +151,12 @@ <H2 ALIGN=CENTER>
152
151
< LI > < A HREF ="../../include/storage/proc.h "> Proc Header</ A > - information
153
152
about each backend, including locks held/waiting, indexed by process id
154
153
</ UL >
154
+
155
155
Each data structure is created by calling < A
156
- HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitStruct(),</ A > and
157
- the lookups are created by
158
- < A HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitHash().</ A >
159
- < P >
156
+ HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitStruct(),</ A > and the
157
+ lookups are created by < A
158
+ HREF ="../../backend/storage/ipc/shmem.c "> ShmemInitHash().</ A > < P >
159
+
160
160
161
161
< HR SIZE ="2 " NOSHADE >
162
162
< SMALL >
0 commit comments