2 $Header: /cvsroot/pgsql/doc/src/sgml/geqo.sgml,v 1.11 2000/08/23 05:59:02 thomas Exp $
9 <firstname>Martin</firstname>
10 <surname>Utesch</surname>
13 University of Mining and Technology
16 Institute of Automatic Control
28 <date>1997-10-02</date>
31 <title>Genetic Query Optimization in Database Systems</title>
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.
44 <title>Query Handling as a Complex Optimization Problem</title>
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.
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
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.
77 Performance difficulties within exploring the space of possible query
78 plans arose the demand for a new optimization technique being developed.
82 In the following we propose the implementation of a <firstterm>Genetic Algorithm</firstterm>
83 as an option for the database query optimization problem.
88 <title>Genetic Algorithms (<acronym>GA</acronym>)</title>
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>.
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>.
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.
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).
122 Structured Diagram of a <acronym>GA</acronym>:
123 ---------------------------
125 P(t) generation of ancestors at a time t
126 P''(t) generation of descendants at a time t
128 +=========================================+
129 |>>>>>>>>>>> Algorithm GA <<<<<<<<<<<<<<|
130 +=========================================+
131 | INITIALIZE t := 0 |
132 +=========================================+
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 | +-------------------------------------+
148 +===+=====================================+
154 <title>Genetic Query Optimization (<acronym>GEQO</acronym>) in Postgres</title>
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
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>.
174 Parts of the <acronym>GEQO</acronym> module are adapted from D. Whitley's Genitor
179 Specific characteristics of the <acronym>GEQO</acronym>
180 implementation in <productname>Postgres</productname>
183 <itemizedlist spacing="compact" mark="bullet">
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;
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>;
203 Mutation as genetic operator is deprecated so that no repair
204 mechanisms are needed to generate legal <acronym>TSP</acronym> tours.
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:
215 <itemizedlist spacing="compact" mark="bullet">
218 Handling of large <command>join</command> queries through non-exhaustive search;
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).
235 <title>Future Implementation Tasks for
236 <productname>ame>Post</productname>ame> <acronym>GEQO</acronym></title>
239 <title>Basic Improvements</title>
242 <title>Improve genetic algorithm parameter settings</title>
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">
252 Optimality of the query plan
265 <title>Find better solution for integer overflow</title>
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.
278 <title>Find solution for exhausted memory</title>
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 :-(
294 <bibliography id="geqo-biblio">
298 <para>Reference information for <acronym>GEQ</acronym> algorithms.
304 The Hitch-Hiker's Guide to Evolutionary Computation
308 <firstname>Jörg</firstname>
309 <surname>Heitkötter</surname>
312 <firstname>David</firstname>
313 <surname>Beasley</surname>
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>.
332 The Design and Implementation of the Postgres Query Optimizer
336 <firstname>Z.</firstname>
337 <surname>Fong</surname>
342 University of California, Berkeley Computer Science Department
347 File <filename>planner/Report.ps</filename> in the 'postgres-papers' distribution.
354 Fundamentals of Database Systems
358 <firstname>R.</firstname>
359 <surname>Elmasri</surname>
362 <firstname>S.</firstname>
363 <surname>Navathe</surname>
368 The Benjamin/Cummings Pub., Inc.
379 <!-- Keep this comment at the end of the file
384 sgml-minimize-attributes:nil
385 sgml-always-quote-attributes: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