记录一下,今天看书的时候看到这里的时候一直不明白Hindex是怎么算出来的。
3.2.2.1. Start-Up Cost
The start-up cost of the index scan is the cost to read the index pages to access to the first tuple in the target table, and it is defined by the following equation:
where HindexHindex is the height of the index tree.
In this case, according to (3), Nindex,tupleNindex,tuple is 10000; HindexHindex is 1; cpu_operator_costcpu_operator_cost is 0.0025 (by default). Thus,
‘start-up cost’={ceil(log2(10000))+(1+1)×50}×0.0025=0.285.
结果发现不需要去估算直接bt_metap返回就可以啦
taria=# select * from bt_metap('idx_t1_id'); magic | version | root | level | fastroot | fastlevel | oldest_xact | last_cleanup_num_tuples | allequalimage --------+---------+------+-------+----------+-----------+-------------+-------------------------+--------------- 340322 | 4 | 1 | 0 | 1 | 0 | 0 | -1 | t (1 row)
Reference
一个有趣的SQL优化案例__一个有趣的SQL优化案例__PostgreSQL中文社区: 世界上功能最强大的开源数据库...