From f5513484171e26456a76a5cdeaad0dbf41980dd8 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 22 Oct 2007 21:34:33 +0000 Subject: [PATCH] Clarify example of planner cost computation, per a suggestion from James Shaw. Also update a couple of examples to reflect 8.3's improved plan-printing code. --- doc/src/sgml/perform.sgml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml index df90f37438..1d3b8484f5 100644 --- a/doc/src/sgml/perform.sgml +++ b/doc/src/sgml/perform.sgml @@ -1,4 +1,4 @@ - + Performance Tips @@ -164,10 +164,11 @@ SELECT relpages, reltuples FROM pg_class WHERE relname = 'tenk1'; you will find out that tenk1 has 358 disk - pages and 10000 rows. So the cost is estimated at 358 page - reads, costing apiece (1.0 by - default), plus 10000 * which is - 0.01 by default. + pages and 10000 rows. The estimated cost is (disk pages read * + ) + (rows scanned * + ). By default, + seq_page_cost is 1.0 and cpu_tuple_cost is 0.01. + So the estimated cost is (358 * 1.0) + (10000 * 0.01) = 458. @@ -189,7 +190,8 @@ EXPLAIN SELECT * FROM tenk1 WHERE unique1 < 7000; The estimate of output rows has gone down because of the WHERE clause. However, the scan will still have to visit all 10000 rows, so the cost - hasn't decreased; in fact it has gone up a bit to reflect the extra CPU + hasn't decreased; in fact it has gone up a bit (by 10000 * , to be exact) to reflect the extra CPU time spent checking the WHERE condition. @@ -310,7 +312,7 @@ EXPLAIN SELECT * FROM tenk1 t1, tenk2 t2 WHERE t1.unique1 < 100 AND t1.unique -> Bitmap Index Scan on tenk1_unique1 (cost=0.00..2.37 rows=106 width=0) Index Cond: (unique1 < 100) -> Index Scan using tenk2_unique2 on tenk2 t2 (cost=0.00..3.01 rows=1 width=244) - Index Cond: ("outer".unique2 = t2.unique2) + Index Cond: (t2.unique2 = t1.unique2) @@ -356,7 +358,7 @@ EXPLAIN SELECT * FROM tenk1 t1, tenk2 t2 WHERE t1.unique1 < 100 AND t1.unique QUERY PLAN ------------------------------------------------------------------------------------------ Hash Join (cost=232.61..741.67 rows=106 width=488) - Hash Cond: ("outer".unique2 = "inner".unique2) + Hash Cond: (t2.unique2 = t1.unique2) -> Seq Scan on tenk2 t2 (cost=0.00..458.00 rows=10000 width=244) -> Hash (cost=232.35..232.35 rows=106 width=244) -> 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 -> 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) Index Cond: (unique1 < 100) -> 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) - Index Cond: ("outer".unique2 = t2.unique2) + Index Cond: (t2.unique2 = t1.unique2) Total runtime: 14.452 ms