官术网_书友最值得收藏!

Deploying simple indexes

Firing up more worker processes to scan ever larger tables is sometimes not the solution. Reading entire tables to find just a single row is usually not a good idea. Therefore, it makes sense to create indexes:

test=# CREATE INDEX idx_id ON t_test (id); 
CREATE INDEX
test=# SELECT * FROM t_test WHERE id = 43242;
id | name
-------+------
43242 | hans
(1 row)
Time: 0.259 ms

PostgreSQL uses Lehman-Yao's high concurrency B-tree for standard indexes. Along with some PostgreSQL specific optimizations, those trees provide end users with excellent performance. The most important thing is that Lehman-Yao allows you to run many operations (reading and writing) on the very same index at the same time, which helps to improve throughput dramatically.

However, indexes are not for free:

test=# \di+ 
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+--------+-------+-------+--------+-------+-------------
public | idx_id | index | hs | t_test | 86 MB |
(1 row)

As you can see, our index containing 4 million rows will eat up 86 MB of disk space. In addition to that, writes to the table will be slower because the index has to be kept in sync all the time.

主站蜘蛛池模板: 保定市| 潢川县| 罗城| 南阳市| 延寿县| 巍山| 仙游县| 红河县| 郑州市| 高青县| 通渭县| 寿宁县| 永寿县| 鹤岗市| 崇仁县| 铁岭市| 和平区| 雅江县| 尼木县| 武乡县| 阳东县| 墨玉县| 台安县| 红安县| 浑源县| 南江县| 志丹县| 定安县| 北海市| 皋兰县| 海兴县| 南宫市| 建水县| 康定县| 金秀| 江山市| 桐庐县| 安多县| 根河市| 肥城市| 教育|