1- <!-- $PostgreSQL: pgsql/doc/src/sgml/perform.sgml,v 1.65 2007/09/26 22:36:30 tgl Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/perform.sgml,v 1.66 2007/10/22 21:34:33 tgl Exp $ -->
22
33 <chapter id="performance-tips">
44 <title>Performance Tips</title>
@@ -164,10 +164,11 @@ SELECT relpages, reltuples FROM pg_class WHERE relname = 'tenk1';
164164</programlisting>
165165
166166 you will find out that <classname>tenk1</classname> has 358 disk
167- pages and 10000 rows. So the cost is estimated at 358 page
168- reads, costing <xref linkend="guc-seq-page-cost"> apiece (1.0 by
169- default), plus 10000 * <xref linkend="guc-cpu-tuple-cost"> which is
170- 0.01 by default.
167+ pages and 10000 rows. The estimated cost is (disk pages read *
168+ <xref linkend="guc-seq-page-cost">) + (rows scanned *
169+ <xref linkend="guc-cpu-tuple-cost">). By default,
170+ <varname>seq_page_cost</> is 1.0 and <varname>cpu_tuple_cost</> is 0.01.
171+ So the estimated cost is (358 * 1.0) + (10000 * 0.01) = 458.
171172 </para>
172173
173174 <para>
@@ -189,7 +190,8 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 < 7000;
189190 The estimate of output rows has gone down because of the <literal>WHERE</>
190191 clause.
191192 However, the scan will still have to visit all 10000 rows, so the cost
192- hasn't decreased; in fact it has gone up a bit to reflect the extra CPU
193+ hasn't decreased; in fact it has gone up a bit (by 10000 * <xref
194+ linkend="guc-cpu-operator-cost">, to be exact) to reflect the extra CPU
193195 time spent checking the <literal>WHERE</> condition.
194196 </para>
195197
@@ -310,7 +312,7 @@ EXPLAIN SELECT * FROM tenk1 t1, tenk2 t2 WHERE t1.unique1 < 100 AND t1.unique
310312 -> Bitmap Index Scan on tenk1_unique1 (cost=0.00..2.37 rows=106 width=0)
311313 Index Cond: (unique1 < 100)
312314 -> Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.00..3.01 rows=1 width=244)
313- Index Cond: ("outer" .unique2 =t2 .unique2)
315+ Index Cond: (t2 .unique2 =t1 .unique2)
314316</programlisting>
315317 </para>
316318
@@ -356,7 +358,7 @@ EXPLAIN SELECT * FROM tenk1 t1, tenk2 t2 WHERE t1.unique1 < 100 AND t1.unique
356358 QUERY PLAN
357359------------------------------------------------------------------------------------------
358360 Hash Join (cost=232.61..741.67 rows=106 width=488)
359- Hash Cond: ("outer" .unique2 ="inner" .unique2)
361+ Hash Cond: (t2 .unique2 =t1 .unique2)
360362 -> Seq Scan on tenk2 t2 (cost=0.00..458.00 rows=10000 width=244)
361363 -> Hash (cost=232.35..232.35 rows=106 width=244)
362364 -> Bitmap Heap Scan on tenk1 t1 (cost=2.37..232.35 rows=106 width=244)
@@ -395,7 +397,7 @@ EXPLAIN ANALYZE SELECT * FROM tenk1 t1, tenk2 t2 WHERE t1.unique1 < 100 AND t
395397 -> Bitmap Index Scan on tenk1_unique1 (cost=0.00..2.37 rows=106 width=0) (actual time=0.546..0.546 rows=100 loops=1)
396398 Index Cond: (unique1 < 100)
397399 -> Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.00..3.01 rows=1 width=244) (actual time=0.067..0.078 rows=1 loops=100)
398- Index Cond: ("outer" .unique2 =t2 .unique2)
400+ Index Cond: (t2 .unique2 =t1 .unique2)
399401 Total runtime: 14.452 ms
400402</screen>
401403