根据向网络牛人发问整理得到:
random_page_cost = 4
seq_page_cost = 1
cpu_tuple_cost =0.01
cpu_index_tuple_cost =0.005
cpu_operator_cost =0.0025
postgres=# select relpages, reltuples from pg_class where relname = 'pg_proc';
relpages | reltuples
----------+-----------
62 | 2490
postgres=# select relpages, reltuples from pg_class where relname = 'pg_proc_oid_index'; relpages | reltuples
----------+-----------
9 | 2490
我的执行计划:
postgres=# explain SELECT * FROM pg_proc where oid=1;
QUERY PLAN
-----------------------------------------------------------------------------------
Index Scan using pg_proc_oid_index on pg_proc (cost=0.00..8.27 rows=1 width=548)
Index Cond: (oid = 1::oid)
(2 rows)
8.27 是怎么来的呢?修改上述的各个参数观察结果的变化,可以得知:
cost = 2*random_page_cost + cpu_tuple_cost +cpu_index_tuple_cost + 100* cpu_operator_cost
其中 random_page_cost *2 ,是一个page 读用于index page, 另一个用于读 data page。
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/11/09/2762120.html,如需转载请自行联系原作者