]> granicus.if.org Git - postgresql/blob - doc/src/sgml/geqo.sgml
Fix several <ulink> tags which refer to e-mail addresses
[postgresql] / doc / src / sgml / geqo.sgml
1 <!--
2 $Header: /cvsroot/pgsql/doc/src/sgml/geqo.sgml,v 1.11 2000/08/23 05:59:02 thomas Exp $
3 Genetic Optimizer
4 -->
5
6  <chapter id="geqo">
7   <docinfo>
8    <author>
9     <firstname>Martin</firstname>
10     <surname>Utesch</surname>
11     <affiliation>
12      <orgname>
13       University of Mining and Technology
14      </orgname>
15      <orgdiv>
16       Institute of Automatic Control
17      </orgdiv>
18      <address>
19       <city>
20        Freiberg
21       </city>
22       <country>
23        Germany
24       </country>
25      </address>
26     </affiliation>
27    </author>
28    <date>1997-10-02</date>
29   </docinfo>
30
31   <title>Genetic Query Optimization in Database Systems</title>
32
33   <para>
34    <note>
35     <title>Author</title>
36     <para>
37      Written by <ulink url="mailto:utesch@aut.tu-freiberg.de">Martin Utesch</ulink>
38      for the Institute of Automatic Control at the University of Mining and Technology in Freiberg, Germany.
39     </para>
40    </note>
41   </para>
42
43   <sect1>
44    <title>Query Handling as a Complex Optimization Problem</title>
45
46    <para>
47     Among all relational operators the most difficult one to process and
48     optimize is the <firstterm>join</firstterm>. The number of alternative plans to answer a query
49     grows exponentially with the number of <command>join</command>s included in it. Further
50     optimization effort is caused by the support of a variety of
51     <firstterm>join methods</firstterm>
52     (e.g., nested loop, index scan, merge join in <productname>Postgres</productname>) to
53     process individual <command>join</command>s and a diversity of
54     <firstterm>indices</firstterm> (e.g., r-tree,
55     b-tree, hash in <productname>Postgres</productname>) as access paths for relations.
56    </para>
57
58    <para>
59     The current <productname>Postgres</productname> optimizer
60     implementation performs a <firstterm>near-
61      exhaustive search</firstterm> over the space of alternative strategies. This query
62     optimization technique is inadequate to support database application
63     domains that involve the need for extensive queries, such as artificial
64     intelligence.
65    </para>
66
67    <para>
68     The Institute of Automatic Control at the University of Mining and
69     Technology, in Freiberg, Germany, encountered the described problems as its
70     folks wanted to take the <productname>Postgres</productname> DBMS as the backend for a decision
71     support knowledge based system for the maintenance of an electrical
72     power grid. The DBMS needed to handle large <command>join</command> queries for the
73     inference machine of the knowledge based system.
74    </para>
75
76    <para>
77     Performance difficulties within exploring the space of possible query
78     plans arose the demand for a new optimization technique being developed.
79    </para>
80
81    <para>
82     In the following we propose the implementation of a <firstterm>Genetic Algorithm</firstterm>
83     as an option for the database query optimization problem.
84    </para>
85   </sect1>
86
87   <sect1>
88    <title>Genetic Algorithms (<acronym>GA</acronym>)</title>
89
90    <para>
91     The <acronym>GA</acronym> is a heuristic optimization method which operates through 
92     determined, randomized search. The set of possible solutions for the
93     optimization problem is considered as a
94     <firstterm>erm>popula</firstterm>erm> of <firstterm>individuals</firstterm>.
95     The degree of adaption of an individual to its environment is specified
96     by its <firstterm>fitness</firstterm>.
97    </para>
98
99    <para>
100     The coordinates of an individual in the search space are represented
101     by <firstterm>chromosomes</firstterm>, in essence a set of character
102     strings. A <firstterm>gene</firstterm> is a
103     subsection of a chromosome which encodes the value of a single parameter
104     being optimized. Typical encodings for a gene could be <firstterm>binary</firstterm> or
105     <firstterm>integer</firstterm>.
106    </para>
107
108    <para>
109     Through simulation of the evolutionary operations <firstterm>recombination</firstterm>,
110     <firstterm>mutation</firstterm>, and
111     <firstterm>selection</firstterm> new generations of search points are found
112     that show a higher average fitness than their ancestors.
113    </para>
114
115    <para>
116     According to the "comp.ai.genetic" <acronym>FAQ</acronym> it cannot be stressed too
117     strongly that a <acronym>GA</acronym> is not a pure random search for a solution to a
118     problem. A <acronym>GA</acronym> uses stochastic processes, but the result is distinctly
119     non-random (better than random). 
120
121     <programlisting>
122 Structured Diagram of a <acronym>GA</acronym>:
123 ---------------------------
124
125 P(t)    generation of ancestors at a time t
126 P''(t)  generation of descendants at a time t
127
128 +=========================================+
129 |>>>>>>>>>>>  Algorithm GA  <<<<<<<<<<<<<<|
130 +=========================================+
131 | INITIALIZE t := 0                       |
132 +=========================================+
133 | INITIALIZE P(t)                         |
134 +=========================================+
135 | evalute FITNESS of P(t)                 |
136 +=========================================+
137 | while not STOPPING CRITERION do         |
138 |   +-------------------------------------+
139 |   | P'(t)  := RECOMBINATION{P(t)}       |
140 |   +-------------------------------------+
141 |   | P''(t) := MUTATION{P'(t)}           |
142 |   +-------------------------------------+
143 |   | P(t+1) := SELECTION{P''(t) + P(t)}  |
144 |   +-------------------------------------+
145 |   | evalute FITNESS of P''(t)           |
146 |   +-------------------------------------+
147 |   | t := t + 1                          |
148 +===+=====================================+
149     </programlisting>
150    </para>
151   </sect1>
152
153   <sect1>
154    <title>Genetic Query Optimization (<acronym>GEQO</acronym>) in Postgres</title>
155
156    <para>
157     The <acronym>GEQO</acronym> module is intended for the solution of the query
158     optimization problem similar to a traveling salesman problem (<acronym>TSP</acronym>).
159     Possible query plans are encoded as integer strings. Each string
160     represents the <command>join</command> order from one relation of the query to the next.
161     E. g., the query tree
162     <programlisting>
163    /\
164   /\ 2
165  /\ 3
166 4  1
167     </programlisting>
168     is encoded by the integer string '4-1-3-2',
169     which means, first join relation '4' and '1', then '3', and
170     then '2', where 1, 2, 3, 4 are relids in <productname>Postgres</productname>.
171    </para>
172
173    <para>
174     Parts of the <acronym>GEQO</acronym> module are adapted from D. Whitley's Genitor
175     algorithm.
176    </para>
177
178    <para>
179     Specific characteristics of the <acronym>GEQO</acronym>
180     implementation in <productname>Postgres</productname>
181     are:
182
183     <itemizedlist spacing="compact" mark="bullet">
184      <listitem>
185       <para>
186        Usage of a <firstterm>steady state</firstterm> <acronym>GA</acronym> (replacement of the least fit
187        individuals in a population, not whole-generational replacement)
188        allows fast convergence towards improved query plans. This is
189        essential for query handling with reasonable time;
190       </para>
191      </listitem>
192
193      <listitem>
194       <para>
195        Usage of <firstterm>edge recombination crossover</firstterm> which is especially suited
196        to keep edge losses low for the solution of the
197        <acronym>cro</acronym>cronym> by means of a <acronym>GA</acronym>;
198       </para>
199      </listitem>
200
201      <listitem>
202       <para>
203        Mutation as genetic operator is deprecated so that no repair
204        mechanisms are needed to generate legal <acronym>TSP</acronym> tours.
205       </para>
206      </listitem>
207     </itemizedlist>
208    </para>
209
210    <para>
211     The <acronym>GEQO</acronym> module gives the following benefits to
212     the <productname>Postgres</productname> DBMS
213     compared to the <productname>Postgres</productname> query optimizer implementation:
214
215     <itemizedlist spacing="compact" mark="bullet">
216      <listitem>
217       <para>
218        Handling of large <command>join</command> queries through non-exhaustive search;
219       </para>
220      </listitem>
221
222      <listitem>
223       <para>
224        Improved cost size approximation of query plans since no longer
225        plan merging is needed (the <acronym>GEQO</acronym> module evaluates the cost for a
226        query plan as an individual).
227       </para>
228      </listitem>
229     </itemizedlist>
230    </para>
231
232   </sect1>
233
234   <sect1>
235    <title>Future Implementation Tasks for
236     <productname>ame>Post</productname>ame> <acronym>GEQO</acronym></title>
237
238    <sect2>
239     <title>Basic Improvements</title>
240
241     <sect3>
242      <title>Improve genetic algorithm parameter settings</title>
243
244      <para>
245       In file <filename>backend/optimizer/geqo/geqo_params.c</filename>, routines
246       <function>gimme_pool_size</function> and <function>gimme_number_generations</function>,
247       we have to find a compromise for the parameter settings
248       to satisfy two competing demands:
249       <itemizedlist spacing="compact">
250        <listitem>
251         <para>
252          Optimality of the query plan
253         </para>
254        </listitem>
255        <listitem>
256         <para>
257          Computing time
258         </para>
259        </listitem>
260       </itemizedlist>
261      </para>
262     </sect3>
263
264     <sect3>
265      <title>Find better solution for integer overflow</title>
266
267      <para>
268       In file <filename>backend/optimizer/geqo/geqo_eval.c</filename>, routine
269       <function>geqo_joinrel_size</function>,
270       the present hack for MAXINT overflow is to set the <productname>Postgres</productname> integer
271       value of <structfield>rel->size</structfield> to its logarithm.
272       Modifications of <structname>Rel</structname> in <filename>backend/nodes/relation.h</filename> will
273       surely have severe impacts on the whole <productname>Postgres</productname> implementation.
274      </para>
275     </sect3>
276
277     <sect3>
278      <title>Find solution for exhausted memory</title>
279
280      <para>
281       Memory exhaustion may occur with more than 10 relations involved in a query.
282       In file <filename>backend/optimizer/geqo/geqo_eval.c</filename>, routine
283       <function>gimme_tree</function> is recursively called.
284       Maybe I forgot something to be freed correctly, but I dunno what.
285       Of course the <structname>rel</structname> data structure of the
286       <command>join</command> keeps growing and
287       growing the more relations are packed into it.
288       Suggestions are welcome :-(
289      </para>
290     </sect3>
291    </sect2>
292
293
294    <bibliography id="geqo-biblio">
295     <title>
296      References
297     </title>
298     <para>Reference information for <acronym>GEQ</acronym> algorithms.
299     </para>
300     <biblioentry>
301
302      <bookbiblio>
303       <title>
304        The Hitch-Hiker's Guide to Evolutionary Computation
305       </title>
306       <authorgroup>
307        <author>
308         <firstname>J&ouml;rg</firstname>
309         <surname>Heitk&ouml;tter</surname>
310        </author>
311        <author>
312         <firstname>David</firstname>
313         <surname>Beasley</surname>
314        </author>
315       </authorgroup>
316       <publisher>
317        <publishername>
318         InterNet resource
319        </publishername>
320       </publisher>
321       <abstract>
322        <para>
323         FAQ in <ulink url="news://comp.ai.genetic">comp.ai.genetic</ulink>
324         is available at <ulink
325          url="ftp://ftp.Germany.EU.net/pub/research/softcomp/EC/Welcome.html">Encore</ulink>.
326        </para>
327       </abstract>
328      </bookbiblio>
329
330      <bookbiblio>
331       <title>
332        The Design and Implementation of the Postgres Query Optimizer
333       </title>
334       <authorgroup>
335        <author>
336         <firstname>Z.</firstname>
337         <surname>Fong</surname>
338        </author>
339       </authorgroup>
340       <publisher>
341        <publishername>
342         University of California, Berkeley Computer Science Department
343        </publishername>
344       </publisher>
345       <abstract>
346        <para>
347         File <filename>planner/Report.ps</filename> in the 'postgres-papers' distribution.
348        </para>
349       </abstract>
350      </bookbiblio>
351
352      <bookbiblio>
353       <title>
354        Fundamentals of Database Systems
355       </title>
356       <authorgroup>
357        <author>
358         <firstname>R.</firstname>
359         <surname>Elmasri</surname>
360        </author>
361        <author>
362         <firstname>S.</firstname>
363         <surname>Navathe</surname>
364        </author>
365       </authorgroup>
366       <publisher>
367        <publishername>
368         The Benjamin/Cummings Pub., Inc.
369        </publishername>
370       </publisher>
371      </bookbiblio>
372
373     </biblioentry>
374    </bibliography>
375
376   </sect1>
377  </chapter>
378
379 <!-- Keep this comment at the end of the file
380 Local variables:
381 mode:sgml
382 sgml-omittag:nil
383 sgml-shorttag:t
384 sgml-minimize-attributes:nil
385 sgml-always-quote-attributes:t
386 sgml-indent-step:1
387 sgml-indent-data:t
388 sgml-parent-document:nil
389 sgml-default-dtd-file:"./reference.ced"
390 sgml-exposed-tags:nil
391 sgml-local-catalogs:("/usr/lib/sgml/catalog")
392 sgml-local-ecat-files:nil
393 End:
394 -->