1
- <!-- $PostgreSQL: pgsql/doc/src/sgml/perform.sgml,v 1.67 2007/11 /28 15:42 :31 petere Exp $ -->
1
+ <!-- $PostgreSQL: pgsql/doc/src/sgml/perform.sgml,v 1.68 2007/12 /28 21:03 :31 tgl Exp $ -->
2
2
3
3
<chapter id="performance-tips">
4
4
<title>Performance Tips</title>
8
8
</indexterm>
9
9
10
10
<para>
11
- Query performance can be affected by many things. Some of these can
11
+ Query performance can be affected by many things. Some of these can
12
12
be manipulated by the user, while others are fundamental to the underlying
13
13
design of the system. This chapter provides some hints about understanding
14
14
and tuning <productname>PostgreSQL</productname> performance.
@@ -138,7 +138,7 @@ EXPLAIN SELECT * FROM tenk1;
138
138
Rows output is a little tricky because it is <emphasis>not</emphasis> the
139
139
number of rows processed or scanned by the plan node. It is usually less,
140
140
reflecting the estimated selectivity of any <literal>WHERE</>-clause
141
- conditions that are being
141
+ conditions that are being
142
142
applied at the node. Ideally the top-level rows estimate will
143
143
approximate the number of rows actually returned, updated, or deleted
144
144
by the query.
@@ -469,8 +469,8 @@ EXPLAIN ANALYZE SELECT * FROM tenk1 t1, tenk2 t2 WHERE t1.unique1 < 100 AND t
469
469
One component of the statistics is the total number of entries in
470
470
each table and index, as well as the number of disk blocks occupied
471
471
by each table and index. This information is kept in the table
472
- <link linkend="catalog-pg-class"><structname>pg_class</structname></link>, in
473
- the columns <structfield>reltuples</structfield> and
472
+ <link linkend="catalog-pg-class"><structname>pg_class</structname></link>,
473
+ in the columns <structfield>reltuples</structfield> and
474
474
<structfield>relpages</structfield>. We can look at it with
475
475
queries similar to this one:
476
476
@@ -493,7 +493,7 @@ SELECT relname, relkind, reltuples, relpages FROM pg_class WHERE relname LIKE 't
493
493
</para>
494
494
495
495
<para>
496
- For efficiency reasons, <structfield>reltuples</structfield>
496
+ For efficiency reasons, <structfield>reltuples</structfield>
497
497
and <structfield>relpages</structfield> are not updated on-the-fly,
498
498
and so they usually contain somewhat out-of-date values.
499
499
They are updated by <command>VACUUM</>, <command>ANALYZE</>, and a
@@ -517,7 +517,8 @@ SELECT relname, relkind, reltuples, relpages FROM pg_class WHERE relname LIKE 't
517
517
<firstterm>selectivity</> of <literal>WHERE</> clauses, that is,
518
518
the fraction of rows that match each condition in the
519
519
<literal>WHERE</> clause. The information used for this task is
520
- stored in the <link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
520
+ stored in the
521
+ <link linkend="catalog-pg-statistic"><structname>pg_statistic</structname></link>
521
522
system catalog. Entries in <structname>pg_statistic</structname>
522
523
are updated by the <command>ANALYZE</> and <command>VACUUM
523
524
ANALYZE</> commands, and are always approximate even when freshly
@@ -530,7 +531,8 @@ SELECT relname, relkind, reltuples, relpages FROM pg_class WHERE relname LIKE 't
530
531
531
532
<para>
532
533
Rather than look at <structname>pg_statistic</structname> directly,
533
- it's better to look at its view <structname>pg_stats</structname>
534
+ it's better to look at its view
535
+ <link linkend="view-pg-stats"><structname>pg_stats</structname></link>
534
536
when examining the statistics manually. <structname>pg_stats</structname>
535
537
is designed to be more easily readable. Furthermore,
536
538
<structname>pg_stats</structname> is readable by all, whereas
@@ -553,13 +555,8 @@ SELECT attname, n_distinct, most_common_vals FROM pg_stats WHERE tablename = 'ro
553
555
</para>
554
556
555
557
<para>
556
- <structname>pg_stats</structname> is described in detail in
557
- <xref linkend="view-pg-stats">.
558
- </para>
559
-
560
- <para>
561
- The amount of information stored in <structname>pg_statistic</structname>,
562
- in particular the maximum number of entries in the
558
+ The amount of information stored in <structname>pg_statistic</structname>
559
+ by <command>ANALYZE</>, in particular the maximum number of entries in the
563
560
<structfield>most_common_vals</> and <structfield>histogram_bounds</>
564
561
arrays for each column, can be set on a
565
562
column-by-column basis using the <command>ALTER TABLE SET STATISTICS</>
@@ -570,7 +567,12 @@ SELECT attname, n_distinct, most_common_vals FROM pg_stats WHERE tablename = 'ro
570
567
columns with irregular data distributions, at the price of consuming
571
568
more space in <structname>pg_statistic</structname> and slightly more
572
569
time to compute the estimates. Conversely, a lower limit might be
573
- appropriate for columns with simple data distributions.
570
+ sufficient for columns with simple data distributions.
571
+ </para>
572
+
573
+ <para>
574
+ Further details about the planner's use of statistics can be found in
575
+ <xref linkend="planner-stats-details">.
574
576
</para>
575
577
576
578
</sect1>
@@ -913,7 +915,7 @@ SELECT * FROM x, y, a, b, c WHERE something AND somethingelse;
913
915
are designed not to write WAL at all if <varname>archive_mode</varname>
914
916
is off. (They can guarantee crash safety more cheaply by doing an
915
917
<function>fsync</> at the end than by writing WAL.)
916
- This applies to the following commands:
918
+ This applies to the following commands:
917
919
<itemizedlist>
918
920
<listitem>
919
921
<para>
0 commit comments