11<!--
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 $
33-->
44
55 <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
2525 very extensive. Rather, this chapter is intended to help the reader
2626 understand the general sequence of operations that occur within the
2727 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.
2929 </para>
3030
3131 <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
7979 <step>
8080 <para>
8181 The <firstterm>planner/optimizer</firstterm> takes
82- the (rewritten)querytree and creates a
82+ the (rewritten)query tree and creates a
8383 <firstterm>query plan</firstterm> that will be the input to the
8484 <firstterm>executor</firstterm>.
8585 </para>
@@ -183,12 +183,12 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
183183 <title>Parser</title>
184184
185185 <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</> .
192192 </para>
193193
194194 <para>
@@ -201,23 +201,22 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
201201 </para>
202202
203203 <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.
209209 </para>
210210
211211 <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>
221220 or <application>yacc</application> is called.
222221
223222 <note>
@@ -334,15 +333,27 @@ $Header: /cvsroot/pgsql/doc/src/sgml/arch-dev.sgml,v 2.21 2003/06/22 16:16:44 tg
334333 <title>Planner/Optimizer</title>
335334
336335 <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 thesame result and it's the
342- task of the optimizer to estimate the cost ofexecuting each path and
343- find out which one is thecheapest .
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, thequery optimizer
341+ will examine each ofthese possible execution plans, ultimately
342+ selecting the execution plan that will run thefastest .
344343 </para>
345344
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+
346357 <para>
347358 After the cheapest path is determined, a <firstterm>plan tree</>
348359 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
373384 After all feasible plans have been found for scanning single relations,
374385 plans for joining relations are created. The planner/optimizer
375386 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
377388 which a restriction like <literal>where rel1.attr1=rel2.attr2</literal>
378389 exists). Join pairs with no join clause are considered only when there
379390 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
416427 </para>
417428
418429 <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.
430443 </para>
431444 </sect2>
432445 </sect1>