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

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.

主站蜘蛛池模板: 文登市| 澄城县| 尼木县| 中西区| 甘南县| 永泰县| 平谷区| 莱州市| 雷州市| 陆川县| 江西省| 临澧县| 阿荣旗| 高邑县| 淅川县| 大同县| 宜君县| 哈密市| 绥中县| 衡南县| 元氏县| 安达市| 安丘市| 新邵县| 和平县| 靖安县| 东至县| 平湖市| 曲水县| 怀化市| 丹阳市| 汉中市| 大新县| 中阳县| 湘乡市| 阿克| 岳阳市| 泽普县| 芜湖市| 乐安县| 什邡市|