1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>Genetic Query Optimization (GEQO) in PostgreSQL</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.1.15 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Genetic Query Optimizer"
HREF="geqo.html"><LINK
REL="PREVIOUS"
TITLE="Genetic Algorithms"
HREF="geqo-intro2.html"><LINK
REL="NEXT"
TITLE="Further Reading"
HREF="geqo-biblio.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2015-02-02T21:03:01"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.1.15 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="Genetic Algorithms"
HREF="geqo-intro2.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="geqo.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 51. Genetic Query Optimizer</TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="Further Reading"
HREF="geqo-biblio.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="GEQO-PG-INTRO"
>51.3. Genetic Query Optimization (<ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
>) in PostgreSQL</A
></H1
><P
> The <ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
> module approaches the query
optimization problem as though it were the well-known traveling salesman
problem (<ACRONYM
CLASS="ACRONYM"
>TSP</ACRONYM
>).
Possible query plans are encoded as integer strings. Each string
represents the join order from one relation of the query to the next.
For example, the join tree
</P><PRE
CLASS="LITERALLAYOUT"
> /\
/\ 2
/\ 3
4 1</PRE
><P>
is encoded by the integer string '4-1-3-2',
which means, first join relation '4' and '1', then '3', and
then '2', where 1, 2, 3, 4 are relation IDs within the
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> optimizer.
</P
><P
> Specific characteristics of the <ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
>
implementation in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
are:
<P
></P
></P><UL
COMPACT="COMPACT"
><LI
STYLE="list-style-type: disc"
><P
> Usage of a <I
CLASS="FIRSTTERM"
>steady state</I
> <ACRONYM
CLASS="ACRONYM"
>GA</ACRONYM
> (replacement of the least fit
individuals in a population, not whole-generational replacement)
allows fast convergence towards improved query plans. This is
essential for query handling with reasonable time;
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> Usage of <I
CLASS="FIRSTTERM"
>edge recombination crossover</I
>
which is especially suited to keep edge losses low for the
solution of the <ACRONYM
CLASS="ACRONYM"
>TSP</ACRONYM
> by means of a
<ACRONYM
CLASS="ACRONYM"
>GA</ACRONYM
>;
</P
></LI
><LI
STYLE="list-style-type: disc"
><P
> Mutation as genetic operator is deprecated so that no repair
mechanisms are needed to generate legal <ACRONYM
CLASS="ACRONYM"
>TSP</ACRONYM
> tours.
</P
></LI
></UL
><P>
</P
><P
> Parts of the <ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
> module are adapted from D. Whitley's
Genitor algorithm.
</P
><P
> The <ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
> module allows
the <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> query optimizer to
support large join queries effectively through
non-exhaustive search.
</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN94106"
>51.3.1. Generating Possible Plans with <ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
></A
></H2
><P
> The <ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
> planning process uses the standard planner
code to generate plans for scans of individual relations. Then join
plans are developed using the genetic approach. As shown above, each
candidate join plan is represented by a sequence in which to join
the base relations. In the initial stage, the <ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
>
code simply generates some possible join sequences at random. For each
join sequence considered, the standard planner code is invoked to
estimate the cost of performing the query using that join sequence.
(For each step of the join sequence, all three possible join strategies
are considered; and all the initially-determined relation scan plans
are available. The estimated cost is the cheapest of these
possibilities.) Join sequences with lower estimated cost are considered
<SPAN
CLASS="QUOTE"
>"more fit"</SPAN
> than those with higher cost. The genetic algorithm
discards the least fit candidates. Then new candidates are generated
by combining genes of more-fit candidates — that is, by using
randomly-chosen portions of known low-cost join sequences to create
new sequences for consideration. This process is repeated until a
preset number of join sequences have been considered; then the best
one found at any time during the search is used to generate the finished
plan.
</P
><P
> This process is inherently nondeterministic, because of the randomized
choices made during both the initial population selection and subsequent
<SPAN
CLASS="QUOTE"
>"mutation"</SPAN
> of the best candidates. To avoid surprising changes
of the selected plan, each run of the GEQO algorithm restarts its
random number generator with the current <A
HREF="runtime-config-query.html#GUC-GEQO-SEED"
>geqo_seed</A
>
parameter setting. As long as <TT
CLASS="VARNAME"
>geqo_seed</TT
> and the other
GEQO parameters are kept fixed, the same plan will be generated for a
given query (and other planner inputs such as statistics). To experiment
with different search paths, try changing <TT
CLASS="VARNAME"
>geqo_seed</TT
>.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="GEQO-FUTURE"
>51.3.2. Future Implementation Tasks for
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> <ACRONYM
CLASS="ACRONYM"
>GEQO</ACRONYM
></A
></H2
><P
> Work is still needed to improve the genetic algorithm parameter
settings.
In file <TT
CLASS="FILENAME"
>src/backend/optimizer/geqo/geqo_main.c</TT
>,
routines
<CODE
CLASS="FUNCTION"
>gimme_pool_size</CODE
> and <CODE
CLASS="FUNCTION"
>gimme_number_generations</CODE
>,
we have to find a compromise for the parameter settings
to satisfy two competing demands:
<P
></P
></P><UL
COMPACT="COMPACT"
><LI
><P
> Optimality of the query plan
</P
></LI
><LI
><P
> Computing time
</P
></LI
></UL
><P>
</P
><P
> In the current implementation, the fitness of each candidate join
sequence is estimated by running the standard planner's join selection
and cost estimation code from scratch. To the extent that different
candidates use similar sub-sequences of joins, a great deal of work
will be repeated. This could be made significantly faster by retaining
cost estimates for sub-joins. The problem is to avoid expending
unreasonable amounts of memory on retaining that state.
</P
><P
> At a more basic level, it is not clear that solving query optimization
with a GA algorithm designed for TSP is appropriate. In the TSP case,
the cost associated with any substring (partial tour) is independent
of the rest of the tour, but this is certainly not true for query
optimization. Thus it is questionable whether edge recombination
crossover is the most effective mutation procedure.
</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="geqo-intro2.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="geqo-biblio.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Genetic Algorithms</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="geqo.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Further Reading</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
|