14.4. Access Method Support Routines

Strategies aren't usually enough information for the system to figure out how to use an index. In practice, the access methods require additional support routines in order to work. For example, the B-tree access method must be able to compare two keys and determine whether one is greater than, equal to, or less than the other. Similarly, the R-tree access method must be able to compute intersections, unions, and sizes of rectangles. These operations do not correspond to operators used in qualifications in SQL queries; they are administrative routines used by the access methods, internally.

Just as with operators, the operator class identifies which specific functions should play each of these roles for a given data type and semantic interpretation. The index access method specifies the set of functions it needs, and the operator class identifies the correct functions to use by assigning "support function numbers" to them.

B-trees require a single support function, as shown in Table 14-4.

Table 14-4. B-tree Support Functions

FunctionSupport Number
Compare two keys and return an integer less than zero, zero, or greater than zero, indicating whether the first key is less than, equal to, or greater than the second. 1

Hash indexes likewise require one support function, as shown in Table 14-5.

Table 14-5. Hash Support Functions

FunctionSupport Number
Compute the hash value for a key1

R-tree indexes require three support functions, as shown in Table 14-6.

Table 14-6. R-tree Support Functions

FunctionSupport Number
union1
intersection2
size3

GiST indexes require seven support functions, as shown in Table 14-7.

Table 14-7. GiST Support Functions

FunctionSupport Number
consistent1
union2
compress3
decompress4
penalty5
picksplit6
equal7