Access Method Support Routines

PostgreSQL 7.3.4 Documentation
Prev | Chapter 14. Interfacing Extensions To Indexes | Next

# 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

Function | Support 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

Function | Support Number
--- | ---
Compute the hash value for a key | 1

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

Table 14-6. R-tree Support Functions

Function | Support Number
--- | ---
union | 1
intersection | 2
size | 3

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

Table 14-7. GiST Support Functions

Function | Support Number
--- | ---
consistent | 1
union | 2
compress | 3
decompress | 4
penalty | 5
picksplit | 6
equal | 7

Prev | Home | Next
Access Method Strategies | Up | Creating the Operators and Support Routines