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

Understanding PostgreSQL index types

So far only binary trees have been discussed. However, in many cases B-trees are just not enough. Why is that the case? As discussed in this chapter, B-trees are basically based on sorting. Operators <, <=, =, >= and > can be handled using B-trees. The trouble is: not all data types can be sorted in a useful way. Just imagine a polygon. How would you sort those objects in a useful way? Sure, you can sort by the area covered, its length or so, but doing that won't allow you to actually find them using a geometric search.

The solution to the problem is to provide more than just one index type. Each index will serve a special purpose and do exactly what is needed. The following index types are available (as of PostgreSQL 9.6):

test=# SELECT * FROM pg_am; 
amname | amhandler | amtype
--------+-------------+--------
btree | bthandler | i
hash | hashhandler | i
GiST | GiSThandler | i
gin | ginhandler | i
spGiST | spghandler | i
brin | brinhandler | i
(6 rows)

There are six types of indexes. B-trees have already been discussed in great detail but what are those other index types good for? The following sections will outline the purpose of each index type available in PostgreSQL.

Note that there are some extensions out there that can be used on top of what you can see here. Additional index types available on the web are rum, vodka, and in future, cognac.

主站蜘蛛池模板: 秦安县| 林甸县| 孝昌县| 周宁县| 化隆| 黄冈市| 遂昌县| 平陆县| 五台县| 三穗县| 南丰县| 沙雅县| 宜黄县| 浙江省| 城口县| 宁安市| 若羌县| 扎兰屯市| 鲁甸县| 贡山| 仁寿县| 司法| 宁乡县| 丰顺县| 静宁县| 大连市| 西乌珠穆沁旗| 松江区| 博乐市| 灵石县| 双辽市| 灵寿县| 普陀区| 阿巴嘎旗| 涞水县| 惠州市| 南川市| 子长县| 扎赉特旗| 沁源县| 壶关县|