Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8903592

Browse files
committed
Update backend flowchard wording
1 parent6ceebca commit8903592

File tree

1 file changed

+167
-162
lines changed

1 file changed

+167
-162
lines changed

‎src/tools/backend/index.html

Lines changed: 167 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,167 @@
1-
<HTML>
2-
<HEAD>
3-
<TITLE>How PostgreSQL Processes a Query</TITLE>
4-
</HEAD>
5-
<BODYBGCOLOR="#FFFFFF"TEXT="#000000"LINK="#FF0000"VLINK="#A00000"ALINK="#0000FF">
6-
<H1>
7-
How PostgreSQL Processes a Query
8-
</H1>
9-
<H2>
10-
by Bruce Momjian
11-
</H2>
12-
<P>
13-
<IMGsrc="flow.gif"usemap="#flowmap"alt="flowchart">
14-
<MAPname="flowmap"id="flowmap">
15-
<AREAcoords="125,35,245,65"HREF="backend_dirs.html#main"alt="main"></AREA>
16-
<AREAcoords="125,100,245,125"HREF="backend_dirs.html#postmaster"alt="postmaster"></AREA>
17-
<AREAcoords="325,65,450,95"HREF="backend_dirs.html#libpq"alt="libpq"></AREA>
18-
<AREAcoords="125,160,245,190"HREF="backend_dirs.html#tcop"alt="tcop"></AREA>
19-
<AREAcoords="325,160,450,190"HREF="backend_dirs.html#tcop"alt="tcop"></AREA>
20-
<AREAcoords="125,240,245,265"HREF="backend_dirs.html#parser"alt="parser"></AREA>
21-
<AREAcoords="125,300,250,330"HREF="backend_dirs.html#tcop"alt="tcop"></AREA>
22-
<AREAcoords="125,360,250,390"HREF="backend_dirs.html#optimizer"alt="optimizer"></AREA>
23-
<AREAcoords="125,425,245,455"HREF="backend_dirs.html#optimizer_plan"alt="plan"></AREA>
24-
<AREAcoords="125,490,245,515"HREF="backend_dirs.html#executor"alt="executor"></AREA>
25-
<AREAcoords="325,300,450,330"HREF="backend_dirs.html#commands"alt="commands"></AREA>
26-
<AREAcoords="75,575,195,605"HREF="backend_dirs.html#utils"alt="utils"></AREA>
27-
<AREAcoords="235,575,360,605"HREF="backend_dirs.html#catalog"alt="catalog"></AREA>
28-
<AREAcoords="405,575,525,605"HREF="backend_dirs.html#storage"alt="storage"></AREA>
29-
<AREAcoords="155,635,275,665"HREF="backend_dirs.html#access"alt="access"></AREA>
30-
<AREAcoords="325,635,450,665"HREF="backend_dirs.html#nodes"alt="nodes"></AREA>
31-
<AREAcoords="75,705,200,730"HREF="backend_dirs.html#bootstrap"alt="bootstrap"></AREA>
32-
</MAP>
33-
<EM>
34-
Click on an item to see more detail or look at the full
35-
<AHREF="backend_dirs.html">index.</A>
36-
</EM>
37-
<BR>
38-
<BR>
39-
</P>
40-
<P>
41-
42-
A query comes to the backend via data packets arriving through TCP/IP or
43-
Unix Domain sockets. It is loaded into a string, and passed to the
44-
<AHREF="../../backend/parser">parser,</A> where the lexical scanner,
45-
<AHREF="../../backend/parser/scan.l">scan.l,</A> breaks the query up
46-
into tokens(words). The parser uses<A
47-
HREF="../../backend/parser/gram.y">gram.y</A> and the tokens to identify
48-
the query type, and load the proper query-specific structure, like<A
49-
HREF="../../include/nodes/parsenodes.h">CreateStmt</A> or<A
50-
HREF="../../include/nodes/parsenodes.h">SelectStmt.</A></P><P>
51-
52-
53-
The query is then identified as a<I>Utility</I> query or a more complex
54-
query. A<I>Utility</I> query is processed by a query-specific function
55-
in<AHREF="../../backend/commands"> commands.</A> A complex query, like
56-
<I>SELECT, UPDATE,</I> and<I>DELETE</I> requires much more handling.</P><P>
57-
58-
59-
The parser takes a complex query, and creates a
60-
<AHREF="../../include/nodes/parsenodes.h">Query</A> structure that
61-
contains all the elements used by complex queries. Query.qual holds the
62-
<I>WHERE</I> clause qualification, which is filled in by<A
63-
HREF="../../backend/parser/parse_clause.c">transformWhereClause().</A>
64-
Each table referenced in the query is represented by a<A
65-
HREF="../../include/nodes/parsenodes.h"> RangeTableEntry,</A> and they
66-
are linked together to form the<I>range table</I> of the query, which
67-
is generated by<AHREF="../../backend/parser/parse_clause.c">
68-
transformFromClause().</A> Query.rtable holds the query's range table.</P><P>
69-
70-
71-
Certain queries, like<I>SELECT,</I> return columns of data. Other
72-
queries, like<I>INSERT</I> and<I>UPDATE,</I> specify the columns
73-
modified by the query. These column references are converted to<A
74-
HREF="../../include/nodes/primnodes.h">TargetEntry</A> entries, which are
75-
linked together to make up the<I>target list</I> of
76-
the query. The target list is stored in Query.targetList, which is
77-
generated by<A
78-
HREF="../../backend/parser/parse_target.c">transformTargetList().</A></P><P>
79-
80-
81-
Other query elements, like aggregates(<I>SUM()</I>),<I>GROUP BY,</I>
82-
and<I>ORDER BY</I> are also stored in their own Query fields.</P><P>
83-
84-
85-
The next step is for the Query to be modified by any<I>VIEWS</I> or
86-
<I>RULES</I> that may apply to the query. This is performed by the<A
87-
HREF="../../backend/rewrite">rewrite</A> system.</P><P>
88-
89-
90-
The<AHREF="../../backend/optimizer">optimizer</A> takes the Query
91-
structure and generates an optimal<A
92-
HREF="../../include/nodes/plannodes.h">Plan,</A> which contains the
93-
operations to be performed to execute the query. The<A
94-
HREF="../../backend/optimizer/path">path</A> module determines the best
95-
table join order and join type of each table in the RangeTable, using
96-
Query.qual(<I>WHERE</I> clause) to consider optimal index usage.</P><P>
97-
98-
99-
The Plan is then passed to the<A
100-
HREF="../../backend/executor">executor</A> for execution, and the result
101-
returned to the client. The Plan actually as set of nodes, arranged in
102-
a tree structure with a top-level node, and various sub-nodes as
103-
children.</P><P>
104-
105-
There are many other modules that support this basic functionality. They
106-
can be accessed by clicking on the flowchart.</P>
107-
108-
109-
<HR><P>
110-
111-
112-
Another area of interest is the shared memory area, which contains data
113-
accessable to all backends. It has recently used data/index blocks,
114-
locks, backend process information, and lookup tables for these
115-
structures:
116-
</P>
117-
118-
<UL>
119-
<LI>ShmemIndex - lookup shared memory addresses using structure names</LI>
120-
<LI><AHREF="../../include/storage/buf_internals.h">Buffer
121-
Descriptor</A> - control header for buffer cache block</LI>
122-
<LI><AHREF="../../include/storage/buf_internals.h">Buffer Block</A> -
123-
data/index buffer cache block</LI>
124-
<LI>Shared Buffer Lookup Table - lookup of buffer cache block addresses
125-
using table name and block number(<A
126-
HREF="../../include/storage/buf_internals.h"> BufferTag</A>)</LI>
127-
<LI>MultiLevelLockTable (ctl) - control structure for each locking
128-
method. Currently, only multi-level locking is used(<A
129-
HREF="../../include/storage/lock.h">LOCKMETHODCTL</A>).</LI>
130-
<LI>MultiLevelLockTable (lock hash) - the<A
131-
HREF="../../include/storage/lock.h">LOCK</A> structure, looked up using
132-
relation, database object ids(<A
133-
HREF="../../include/storage/lock.h">LOCKTAG)</A>. The lock table
134-
structure contains the lock modes(read/write or shared/exclusive) and
135-
circular linked list of backends (<A
136-
HREF="../../include/storage/proc.h">PROC</A> structure pointers) waiting
137-
on the lock.</LI>
138-
<LI>MultiLevelLockTable (xid hash) - lookup of LOCK structure address
139-
using transaction id, LOCK address. It is used to quickly check if the
140-
current transaction already has any locks on a table, rather than having
141-
to search through all the held locks. It also stores the modes
142-
(read/write) of the locks held by the current transaction. The returned
143-
<AHREF="../../include/storage/lock.h">XIDLookupEnt</A> structure also
144-
contains a pointer to the backend's PROC.lockQueue.</LI>
145-
<LI><AHREF="../../include/storage/proc.h">Proc Header</A> - information
146-
about each backend, including locks held/waiting, indexed by process id</LI>
147-
</UL>
148-
149-
<P>Each data structure is created by calling<A
150-
HREF="../../backend/storage/ipc/shmem.c">ShmemInitStruct(),</A> and the
151-
lookups are created by<A
152-
HREF="../../backend/storage/ipc/shmem.c">ShmemInitHash().</A></P>
153-
154-
155-
<HR>
156-
<SMALL>
157-
Maintainer:Bruce Momjian (<A
158-
HREF="mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
159-
Last updated:Mon Aug 10 10:48:06 EDT 1998
160-
</SMALL>
161-
</BODY>
162-
</HTML>
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<htmlxmlns="http://www.w3.org/1999/xhtml">
4+
<head>
5+
<metaname="generator"
6+
content="HTML Tidy for BSD/OS (vers 1st July 2002), see www.w3.org"/>
7+
<title>How PostgreSQL Processes a Query</title>
8+
</head>
9+
<bodybgcolor="#FFFFFF"text="#000000"link="#FF0000"
10+
vlink="#A00000"alink="#0000FF">
11+
<h1>How PostgreSQL Processes a Query</h1>
12+
13+
<h2>by Bruce Momjian</h2>
14+
15+
<p><imgsrc="flow.gif"usemap="#flowmap"alt="flowchart"/>
16+
17+
<em>Click on an item to see more detail or look at the full
18+
<ahref="backend_dirs.html">index.</a></em>
19+
20+
<mapname="flowmap"id="flowmap">
21+
<areacoords="125,35,245,65"href="backend_dirs.html#main"alt="main"/>
22+
<areacoords="125,100,245,125"href="backend_dirs.html#postmaster"alt="postmaster"/>
23+
<areacoords="325,65,450,95"href="backend_dirs.html#libpq"alt="libpq"/>
24+
<areacoords="125,160,245,190"href="backend_dirs.html#tcop"alt="tcop"/>
25+
<areacoords="325,160,450,190"href="backend_dirs.html#tcop"alt="tcop"/>
26+
<areacoords="125,240,245,265"href="backend_dirs.html#parser"alt="parser"/>
27+
<areacoords="125,300,250,330"href="backend_dirs.html#tcop"alt="tcop"/>
28+
<areacoords="125,360,250,390"href="backend_dirs.html#optimizer"alt="optimizer"/>
29+
<areacoords="125,425,245,455"href="backend_dirs.html#optimizer_plan"alt="plan"/>
30+
<areacoords="125,490,245,515"href="backend_dirs.html#executor"alt="executor"/>
31+
<areacoords="325,300,450,330"href="backend_dirs.html#commands"alt="commands"/>
32+
<areacoords="75,575,195,605"href="backend_dirs.html#utils"alt="utils"/>
33+
<areacoords="235,575,360,605"href="backend_dirs.html#catalog"alt="catalog"/>
34+
<areacoords="405,575,525,605"href="backend_dirs.html#storage"alt="storage"/>
35+
<areacoords="155,635,275,665"href="backend_dirs.html#access"alt="access"/>
36+
<areacoords="325,635,450,665"href="backend_dirs.html#nodes"alt="nodes"/>
37+
<areacoords="75,705,200,730"href="backend_dirs.html#bootstrap"alt="bootstrap"/>
38+
</map>
39+
40+
<br/>
41+
42+
<p>A query comes to the backend via data packets arriving through
43+
TCP/IP or Unix Domain sockets. It is loaded into a string, and
44+
passed to the<ahref="../../backend/parser">parser,</a> where the
45+
lexical scanner,<ahref="../../backend/parser/scan.l">scan.l,</a>
46+
breaks the query up into tokens(words). The parser uses<a
47+
href="../../backend/parser/gram.y">gram.y</a> and the tokens to
48+
identify the query type, and load the proper query-specific
49+
structure, like<a
50+
href="../../include/nodes/parsenodes.h">CreateStmt</a> or<a
51+
href="../../include/nodes/parsenodes.h">SelectStmt.</a></p>
52+
53+
<p>The statement is then identified as complex (<i>SELECT / INSERT /
54+
UPDATE / DELETE</i>) or a simple, e.g<i> CREATE USER, ANALYZE,</i>,
55+
etc. Utility commands are processed by statement-specific functions in<a
56+
href="../../backend/commands">backend/commands.</a> Complex statements
57+
require more handling.</p>
58+
59+
<p>The parser takes a complex query, and creates a<a
60+
href="../../include/nodes/parsenodes.h">Query</a> structure that
61+
contains all the elements used by complex queries. Query.qual holds
62+
the<i>WHERE</i> clause qualification, which is filled in by<a
63+
href="../../backend/parser/parse_clause.c">transformWhereClause().</a>
64+
Each table referenced in the query is represented by a<a
65+
href="../../include/nodes/parsenodes.h">RangeTableEntry,</a> and
66+
they are linked together to form the<i>range table</i> of the
67+
query, which is generated by<a
68+
href="../../backend/parser/parse_clause.c">transformFromClause().</a>
69+
Query.rtable holds the query's range table.</p>
70+
71+
<p>Certain queries, like<i>SELECT,</i> return columns of data.
72+
Other queries, like<i>INSERT</i> and<i>UPDATE,</i> specify the
73+
columns modified by the query. These column references are
74+
converted to<a
75+
href="../../include/nodes/primnodes.h">TargetEntry</a> entries,
76+
which are linked together to make up the<i>target list</i> of the
77+
query. The target list is stored in Query.targetList, which is
78+
generated by<a
79+
href="../../backend/parser/parse_target.c">transformTargetList().</a></p>
80+
81+
<p>Other query elements, like aggregates(<i>SUM()</i>),<i>GROUP
82+
BY,</i> and<i>ORDER BY</i> are also stored in their own Query
83+
fields.</p>
84+
85+
<p>The next step is for the Query to be modified by any
86+
<i>VIEWS</i> or<i>RULES</i> that may apply to the query. This is
87+
performed by the<ahref="../../backend/rewrite">rewrite</a>
88+
system.</p>
89+
90+
<p>The<ahref="../../backend/optimizer">optimizer</a> takes the
91+
Query structure and generates an optimal<a
92+
href="../../include/nodes/plannodes.h">Plan,</a> which contains the
93+
operations to be performed to execute the query. The<a
94+
href="../../backend/optimizer/path">path</a> module determines the
95+
best table join order and join type of each table in the
96+
RangeTable, using Query.qual(<i>WHERE</i> clause) to consider
97+
optimal index usage.</p>
98+
99+
<p>The Plan is then passed to the<a
100+
href="../../backend/executor">executor</a> for execution, and the
101+
result returned to the client. The Plan actually as set of nodes,
102+
arranged in a tree structure with a top-level node, and various
103+
sub-nodes as children.</p>
104+
105+
<p>There are many other modules that support this basic
106+
functionality. They can be accessed by clicking on the
107+
flowchart.</p>
108+
109+
<hr/>
110+
<p>Another area of interest is the shared memory area, which
111+
contains data accessable to all backends. It has recently used
112+
data/index blocks, locks, backend process information, and lookup
113+
tables for these structures:</p>
114+
115+
<ul>
116+
<li>ShmemIndex - lookup shared memory addresses using structure
117+
names</li>
118+
119+
<li><ahref="../../include/storage/buf_internals.h">Buffer
120+
Descriptor</a> - control header for buffer cache block</li>
121+
122+
<li><ahref="../../include/storage/buf_internals.h">Buffer
123+
Block</a> - data/index buffer cache block</li>
124+
125+
<li>Shared Buffer Lookup Table - lookup of buffer cache block
126+
addresses using table name and block number(<a
127+
href="../../include/storage/buf_internals.h">BufferTag</a>)</li>
128+
129+
<li>MultiLevelLockTable (ctl) - control structure for each locking
130+
method. Currently, only multi-level locking is used(<a
131+
href="../../include/storage/lock.h">LOCKMETHODCTL</a>).</li>
132+
133+
<li>MultiLevelLockTable (lock hash) - the<a
134+
href="../../include/storage/lock.h">LOCK</a> structure, looked up
135+
using relation, database object ids(<a
136+
href="../../include/storage/lock.h">LOCKTAG)</a>. The lock table
137+
structure contains the lock modes(read/write or shared/exclusive)
138+
and circular linked list of backends (<a
139+
href="../../include/storage/proc.h">PROC</a> structure pointers)
140+
waiting on the lock.</li>
141+
142+
<li>MultiLevelLockTable (xid hash) - lookup of LOCK structure
143+
address using transaction id, LOCK address. It is used to quickly
144+
check if the current transaction already has any locks on a table,
145+
rather than having to search through all the held locks. It also
146+
stores the modes (read/write) of the locks held by the current
147+
transaction. The returned<a
148+
href="../../include/storage/lock.h">XIDLookupEnt</a> structure also
149+
contains a pointer to the backend's PROC.lockQueue.</li>
150+
151+
<li><ahref="../../include/storage/proc.h">Proc Header</a> -
152+
information about each backend, including locks held/waiting,
153+
indexed by process id</li>
154+
</ul>
155+
156+
<p>Each data structure is created by calling<a
157+
href="../../backend/storage/ipc/shmem.c">ShmemInitStruct(),</a> and
158+
the lookups are created by<a
159+
href="../../backend/storage/ipc/shmem.c">ShmemInitHash().</a></p>
160+
161+
<hr/>
162+
<small>Maintainer: Bruce Momjian (<a
163+
href="mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</a>)<br/>
164+
165+
Last updated: Fri May 6 14:22:27 EDT 2005</small>
166+
</body>
167+
</html>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp