|
1 | | -<!-- $PostgreSQL: pgsql/doc/src/sgml/arch-dev.sgml,v 2.29 2007/01/31 20:56:16 momjian Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/arch-dev.sgml,v 2.30 2007/07/21 04:02:41 tgl Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="overview"> |
4 | 4 | <title>Overview of PostgreSQL Internals</title> |
|
345 | 345 | can be executed would take an excessive amount of time and memory |
346 | 346 | space. In particular, this occurs when executing queries |
347 | 347 | involving large numbers of join operations. In order to determine |
348 | | - a reasonable (not optimal) query plan in a reasonable amount of |
349 | | - time, <productname>PostgreSQL</productname> uses a <xref |
350 | | - linkend="geqo" endterm="geqo-title">. |
| 348 | + a reasonable (not necessarily optimal) query plan in a reasonable amount |
| 349 | + of time, <productname>PostgreSQL</productname> uses a <xref |
| 350 | + linkend="geqo" endterm="geqo-title"> when the number of joins |
| 351 | + exceeds a threshold (see <xref linkend="guc-geqo-threshold">). |
351 | 352 | </para> |
352 | 353 | </note> |
353 | 354 |
|
|
380 | 381 | the index's <firstterm>operator class</>, another plan is created using |
381 | 382 | the B-tree index to scan the relation. If there are further indexes |
382 | 383 | present and the restrictions in the query happen to match a key of an |
383 | | - index further plans will be considered. |
| 384 | + index, further plans will be considered. Index scan plans are also |
| 385 | + generated for indexes that have a sort ordering that can match the |
| 386 | + query's <literal>ORDER BY</> clause (if any), or a sort ordering that |
| 387 | + might be useful for merge joining (see below). |
384 | 388 | </para> |
385 | 389 |
|
386 | 390 | <para> |
387 | | - After all feasible plans have been found for scanning single relations, |
388 | | - plans for joining relations are created. The planner/optimizer |
389 | | - preferentially considers joins between any two relations for which there |
390 | | - exist a corresponding join clause in the <literal>WHERE</literal> qualification (i.e. for |
391 | | - which a restriction like <literal>where rel1.attr1=rel2.attr2</literal> |
392 | | - exists). Join pairs with no join clause are considered only when there |
393 | | - is no other choice, that is, a particular relation has no available |
394 | | - join clauses to any other relation. All possible plans are generated for |
395 | | - every join pair considered |
396 | | - by the planner/optimizer. The three possible join strategies are: |
| 391 | + If the query requires joining two or more relations, |
| 392 | + plans for joining relations are considered |
| 393 | + after all feasible plans have been found for scanning single relations. |
| 394 | + The three available join strategies are: |
397 | 395 |
|
398 | 396 | <itemizedlist> |
399 | 397 | <listitem> |
|
439 | 437 | cheapest one. |
440 | 438 | </para> |
441 | 439 |
|
| 440 | + <para> |
| 441 | + If the query uses fewer than <xref linkend="guc-geqo-threshold"> |
| 442 | + relations, a near-exhaustive search is conducted to find the best |
| 443 | + join sequence. The planner preferentially considers joins between any |
| 444 | + two relations for which there exist a corresponding join clause in the |
| 445 | + <literal>WHERE</literal> qualification (i.e. for |
| 446 | + which a restriction like <literal>where rel1.attr1=rel2.attr2</literal> |
| 447 | + exists). Join pairs with no join clause are considered only when there |
| 448 | + is no other choice, that is, a particular relation has no available |
| 449 | + join clauses to any other relation. All possible plans are generated for |
| 450 | + every join pair considered by the planner, and the one that is |
| 451 | + (estimated to be) the cheapest is chosen. |
| 452 | + </para> |
| 453 | + |
| 454 | + <para> |
| 455 | + When <varname>geqo_threshold</varname> is exceeded, the join |
| 456 | + sequences considered are determined by heuristics, as described |
| 457 | + in <xref linkend="geqo">. Otherwise the process is the same. |
| 458 | + </para> |
| 459 | + |
442 | 460 | <para> |
443 | 461 | The finished plan tree consists of sequential or index scans of |
444 | 462 | the base relations, plus nested-loop, merge, or hash join nodes as |
|