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

BRIN indexes

Block range indexes (BRIN) are of great practical use. All indexes discussed until now need quite a lot of disk space. Although a lot of work has gone into shrinking GIN indexes and the like, they still need quite a lot because an index pointer is needed for each entry. So, if there are 10 million entries, there will be 10 million index pointers. Space is the main concern addressed by the BRIN indexes. A BRIN index does not keep an index entry for each tuple but will store the minimum and the maximum value of 128 (default) blocks of data (1 MB). The index is therefore very small but lossy. Scanning the index will return more data than we asked for. PostgreSQL has to filter out these additional rows in a later step.

The following example demonstrates how small a BRIN index really is:

test=# CREATE INDEX idx_brin ON t_test USING brin(id); 
CREATE INDEX
test=# \di+ idx_brin List of relations
Schema | Name | Type | Owner | Table | Size
--------+----------+-------+-------+--------+-------+-------------
public | idx_brin | index | hs | t_test | 48 KB
(1 row)

In my example, the BRIN index is 2,000 times smaller than a standard b-tree. The question naturally arising now is, why don't we always use BRIN indexes? To answer this kind of question, it is important to reflect on the layout of BRIN; the minimum and maximum value for 1 MB are stored. If the data is sorted (high correlation), BRIN is pretty efficient because we can fetch 1 MB of data, scan it, and we are done. However, what if the data is shuffled? In this case, BRIN won't be able to exclude chunks of data anymore because it is very likely that something close to the overall high and the overall low is within 1 MB of data. Therefore, BRIN is mostly made for highly correlated data. In reality, correlated data is quite likely in data warehousing applications. Often, data is loaded every day and therefore dates can be highly correlated.

主站蜘蛛池模板: 呼和浩特市| 梧州市| 郎溪县| 佛学| 讷河市| 微博| 台湾省| 遵化市| 西丰县| 青冈县| 河间市| 读书| 乌什县| 仁怀市| 万宁市| 彭州市| 龙泉市| 葵青区| 济阳县| 禄劝| 徐水县| 新津县| 泽库县| 霍林郭勒市| 淮滨县| 酒泉市| 扬中市| 武汉市| 渝中区| 阳高县| 高州市| 洛扎县| 娱乐| 蛟河市| 将乐县| 堆龙德庆县| 黄骅市| 西吉县| 泾川县| 吉隆县| 南江县|