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 $ -->
2
2
3
3
<chapter id="performance-tips">
4
4
<title>Performance Tips</title>
@@ -164,10 +164,11 @@ SELECT relpages, reltuples FROM pg_class WHERE relname = 'tenk1';
164
164
</programlisting>
165
165
166
166
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.
171
172
</para>
172
173
173
174
<para>
@@ -189,7 +190,8 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 < 7000;
189
190
The estimate of output rows has gone down because of the <literal>WHERE</>
190
191
clause.
191
192
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
193
195
time spent checking the <literal>WHERE</> condition.
194
196
</para>
195
197
@@ -310,7 +312,7 @@ EXPLAIN SELECT * FROM tenk1 t1, tenk2 t2 WHERE t1.unique1 < 100 AND t1.unique
310
312
-> Bitmap Index Scan on tenk1_unique1 (cost=0.00..2.37 rows=106 width=0)
311
313
Index Cond: (unique1 < 100)
312
314
-> 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)
314
316
</programlisting>
315
317
</para>
316
318
@@ -356,7 +358,7 @@ EXPLAIN SELECT * FROM tenk1 t1, tenk2 t2 WHERE t1.unique1 < 100 AND t1.unique
356
358
QUERY PLAN
357
359
------------------------------------------------------------------------------------------
358
360
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)
360
362
-> Seq Scan on tenk2 t2 (cost=0.00..458.00 rows=10000 width=244)
361
363
-> Hash (cost=232.35..232.35 rows=106 width=244)
362
364
-> 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
395
397
-> 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)
396
398
Index Cond: (unique1 < 100)
397
399
-> 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)
399
401
Total runtime: 14.452 ms
400
402
</screen>
401
403
0 commit comments