Understanding PostgreSQL index types

So far, only binary trees have been discussed. However, in many cases, btrees are just not enough. Why is that the case? As discussed in this chapter, btrees are basically based on sorting. Operators <, <=, =, >=, and > can be handled using btrees. The trouble is, not ever data type can be sorted in a useful way. Just imagine a polygon. How would you sort these objects in a useful way? Sure, you can sort by the area covered, its length or so on, but doing this 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 10.0):

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. The btrees 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 the future, cognac.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset