Of course, it is also possible to come up with your own operator classes. The following strategies are supported:
Operation |
Strategy number |
Strictly left of |
1 |
Does not extend to right of |
2 |
Overlaps |
3 |
Does not extend to left of |
4 |
Strictly right of |
5 |
Same |
6 |
Contains |
7 |
Contained by |
8 |
Does not extend above |
9 |
Strictly below |
10 |
Strictly above |
11 |
Does not extend below |
12 |
If you want to write operator classes for GiST, a couple of support functions have to be provided. In the case of a B-tree, there is only one function—GiST indexes provide a lot more:
Function |
Description |
Support function number |
consistent |
This determines whether a key satisfies the query qualifier. Internally, strategies are looked up and checked. |
1 |
union |
Calculates the union of a set of keys. In the case of numeric values, the upper and lower values or a range are computed. It is especially important to geometries. |
2 |
compress |
Computes a compressed representation of a key or value. |
3 |
decompress |
This is the counterpart of the compress function. |
4 |
penalty |
During insertion, the cost of inserting into the tree will be calculated. The cost determines where the new entry will go inside the tree. Therefore, a good penalty function is key to good overall performance from the index. |
5 |
picksplit |
Determines where to move entries in the case of a page split. Some entries have to stay on the old page, while others will go to the new page being created. Having a good picksplit function is essential to good index performance. |
6 |
equal |
The equal function is similar to the same function you have already seen in B-trees. |
7 |
distance |
Calculates the distance (a number) between a key and the query value. The distance function is optional and is needed if KNN search is supported. |
8 |
fetch |
Determines the original representation of a compressed key. This function is needed to handle index-only scans, as supported by the recent version of PostgreSQL. |
9 |
Implementing operator classes for GiST indexes is usually done in C. If you are interested in a good example, I advise you to check out the btree_GiST module in the contrib directory. It shows how to index standard data types using GiST and is a good source of information, as well as inspiration.