1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tgl Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.22 2003/09/29 18:18:35 momjian Exp $
3
3
-->
4
4
5
5
<chapter id="overview">
@@ -25,7 +25,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
25
25
very extensive. Rather, this chapter is intended to help the reader
26
26
understand the general sequence of operations that occur within the
27
27
backend from the point at which a query is received, to the point
28
- when the results are returned to the client.
28
+ at which the results are returned to the client.
29
29
</para>
30
30
31
31
<sect1 id="query-path">
@@ -79,7 +79,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
79
79
<step>
80
80
<para>
81
81
The <firstterm>planner/optimizer</firstterm> takes
82
- the (rewritten) querytree and creates a
82
+ the (rewritten) query tree and creates a
83
83
<firstterm>query plan</firstterm> that will be the input to the
84
84
<firstterm>executor</firstterm>.
85
85
</para>
@@ -183,12 +183,12 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
183
183
<title>Parser</title>
184
184
185
185
<para>
186
- The parser has to check the query string (which arrives as
187
- plain ASCII text) for valid syntax. If the syntax is correct a
188
- <firstterm>parse tree</firstterm> is built up and handed back otherwise an error is
189
- returned. For the implementation the well known Unix
190
- tools <application>lex</application> and <application>yacc</application >
191
- are used .
186
+ The parser has to check the query string (which arrives as plain
187
+ ASCII text) for valid syntax. If the syntax is correct a
188
+ <firstterm>parse tree</firstterm> is built up and handed back;
189
+ otherwise an error is returned. The parser and lexer are
190
+ implemented using the well-known Unix tools <application>yacc</>
191
+ and <application>lex</> .
192
192
</para>
193
193
194
194
<para>
@@ -201,23 +201,22 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
201
201
</para>
202
202
203
203
<para>
204
- The parser is defined in the file <filename>gram.y</filename> and consists of a
205
- set of <firstterm>grammar rules</firstterm> and <firstterm>actions</firstterm>
206
- that are executed
207
- whenever a rule is fired. The code of the actions (which
208
- is actually C-code) is used to build up the parse tree.
204
+ The parser is defined in the file <filename>gram.y</filename> and
205
+ consists of a set of <firstterm>grammar rules</firstterm> and
206
+ <firstterm>actions</firstterm> that are executed whenever a rule
207
+ is fired. The code of the actions (which is actually C code) is
208
+ used to build up the parse tree.
209
209
</para>
210
210
211
211
<para>
212
- The file <filename>scan.l</filename> is transformed to
213
- the C-source file <filename>scan.c</filename>
214
- using the program <application>lex</application>
215
- and <filename>gram.y</filename> is transformed to
216
- <filename>gram.c</filename> using <application>yacc</application>.
217
- After these transformations have taken
218
- place a normal C-compiler can be used to create the
219
- parser. Never make any changes to the generated C-files as they will
220
- be overwritten the next time <application>lex</application>
212
+ The file <filename>scan.l</filename> is transformed to the C
213
+ source file <filename>scan.c</filename> using the program
214
+ <application>lex</application> and <filename>gram.y</filename> is
215
+ transformed to <filename>gram.c</filename> using
216
+ <application>yacc</application>. After these transformations
217
+ have taken place a normal C compiler can be used to create the
218
+ parser. Never make any changes to the generated C files as they
219
+ will be overwritten the next time <application>lex</application>
221
220
or <application>yacc</application> is called.
222
221
223
222
<note>
@@ -334,15 +333,27 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
334
333
<title>Planner/Optimizer</title>
335
334
336
335
<para>
337
- The task of the <firstterm>planner/optimizer</firstterm> is to create an optimal
338
- execution plan. It first considers all possible ways of
339
- <firstterm>scanning</firstterm> and <firstterm>joining</firstterm>
340
- the relations that appear in a
341
- query. All the created paths lead to the same result and it's the
342
- task of the optimizer to estimate the cost of executing each path and
343
- find out which one is the cheapest .
336
+ The task of the <firstterm>planner/optimizer</firstterm> is to
337
+ create an optimal execution plan. A given SQL query (and hence, a
338
+ query tree) can be actually executed in a wide variety of
339
+ different ways, each of which will produce the same set of
340
+ results. If it is computationally feasible, the query optimizer
341
+ will examine each of these possible execution plans, ultimately
342
+ selecting the execution plan that will run the fastest .
344
343
</para>
345
344
345
+ <note>
346
+ <para>
347
+ In some situations, examining each possible way in which a query
348
+ may be executed would take an excessive amount of time and memory
349
+ space. In particular, this occurs when executing queries
350
+ involving large numbers of join operations. In order to determine
351
+ a reasonable (not optimal) query plan in a reasonable amount of
352
+ time, <productname>PostgreSQL</productname> uses a <xref
353
+ linkend="geqo" endterm="geqo-title">.
354
+ </para>
355
+ </note>
356
+
346
357
<para>
347
358
After the cheapest path is determined, a <firstterm>plan tree</>
348
359
is built to pass to the executor. This represents the desired
@@ -373,7 +384,7 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
373
384
After all feasible plans have been found for scanning single relations,
374
385
plans for joining relations are created. The planner/optimizer
375
386
preferentially considers joins between any two relations for which there
376
- exist a corresponding join clause in the WHERE qualification (i.e. for
387
+ exist a corresponding join clause in the <literal> WHERE</literal> qualification (i.e. for
377
388
which a restriction like <literal>where rel1.attr1=rel2.attr2</literal>
378
389
exists). Join pairs with no join clause are considered only when there
379
390
is no other choice, that is, a particular relation has no available
@@ -416,17 +427,19 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
416
427
</para>
417
428
418
429
<para>
419
- The finished plan tree consists of sequential or index scans of the
420
- base relations, plus nestloop, merge, or hash join nodes as needed,
421
- plus any auxiliary steps needed, such as sort nodes or aggregate-function
422
- calculation nodes. Most of these plan node types have the additional
423
- ability to do <firstterm>selection</> (discarding rows that do
424
- not meet a specified boolean condition) and <firstterm>projection</>
425
- (computation of a derived column set based on given column values,
426
- that is, evaluation of scalar expressions where needed). One of
427
- the responsibilities of the planner is to attach selection conditions
428
- from the WHERE clause and computation of required output expressions
429
- to the most appropriate nodes of the plan tree.
430
+ The finished plan tree consists of sequential or index scans of
431
+ the base relations, plus nestloop, merge, or hash join nodes as
432
+ needed, plus any auxiliary steps needed, such as sort nodes or
433
+ aggregate-function calculation nodes. Most of these plan node
434
+ types have the additional ability to do <firstterm>selection</>
435
+ (discarding rows that do not meet a specified boolean condition)
436
+ and <firstterm>projection</> (computation of a derived column set
437
+ based on given column values, that is, evaluation of scalar
438
+ expressions where needed). One of the responsibilities of the
439
+ planner is to attach selection conditions from the
440
+ <literal>WHERE</literal> clause and computation of required
441
+ output expressions to the most appropriate nodes of the plan
442
+ tree.
430
443
</para>
431
444
</sect2>
432
445
</sect1>
0 commit comments