Access Method Support Routines

Sometimes, strategies are not enough information for the system to figure out how to use an index. Some access methods require other 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 user qualifications in SQL queries; they are administrative routines used by the access methods, internally.

In order to manage diverse support routines consistently across all PostgreSQL access methods, pg_am includes a column called amsupport. This column records the number of support routines used by an access method. For B-trees, this number is one: the routine to take two keys and return -1, 0, or +1, depending on whether the first key is less than, equal to, or greater than the second. (Strictly speaking, this routine can return a negative number (< 0), zero, or a non-zero positive number (> 0).)

The amstrategies entry in pg_am is just the number of strategies defined for the access method in question. The procedures for less than, less than or equal, and so on do not appear in pg_am. Similarly, amsupport is just the number of support routines required by the access method. The actual routines are listed elsewhere.

The amorderstrategy entry tells whether the access method supports ordered scan. Zero means it does not; if it does, amorderstrategy is the number of the strategy routine that corresponds to the ordering operator. For example, btree has amorderstrategy = 1 which is the number of its "less than" strategy.