- Mastering PostgreSQL 9.6
- Hans Jurgen Schonig
- 210字
- 2021-07-09 19:57:15
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.
- 火格局的時(shí)空變異及其在電網(wǎng)防火中的應(yīng)用
- Dreamweaver CS3網(wǎng)頁(yè)制作融會(huì)貫通
- Dreamweaver 8中文版商業(yè)案例精粹
- Google App Inventor
- 新手學(xué)電腦快速入門
- Implementing Oracle API Platform Cloud Service
- 網(wǎng)絡(luò)化分布式系統(tǒng)預(yù)測(cè)控制
- 深度學(xué)習(xí)與目標(biāo)檢測(cè)
- ESP8266 Robotics Projects
- 基于敏捷開(kāi)發(fā)的數(shù)據(jù)結(jié)構(gòu)研究
- 工業(yè)機(jī)器人實(shí)操進(jìn)階手冊(cè)
- Mastering MongoDB 4.x
- 天才與算法:人腦與AI的數(shù)學(xué)思維
- Generative Adversarial Networks Projects
- 從機(jī)器學(xué)習(xí)到無(wú)人駕駛