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

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.

主站蜘蛛池模板: 郴州市| 赤水市| 阳谷县| 汝南县| 浙江省| 荔浦县| 株洲市| 阿拉尔市| 淅川县| 禄丰县| 安平县| 星子县| 雷山县| 赤城县| 神农架林区| 龙胜| 平泉县| 庄河市| 枞阳县| 茌平县| 奈曼旗| 永吉县| 明溪县| 横峰县| 丹凤县| 泸定县| 正宁县| 石河子市| 临沧市| 石首市| 朝阳市| 名山县| 湘乡市| 辽阳市| 东兰县| 阿图什市| 堆龙德庆县| 类乌齐县| 于都县| 司法| 临颍县|