The GIN interface has a high level of abstraction, requiring the access method implementer only to implement the semantics of the data type being accessed. The GIN layer itself takes care of concurrency, logging and searching the tree structure.
All it takes to get a GIN access method working is to implement four user-defined methods, which define the behavior of keys in the tree and the relationships between keys, indexed values, and indexable queries. In short, GIN combines extensibility with generality, code reuse, and a clean interface.
The four methods that an index operator class for GIN must provide are:
Compares keys (not indexed values!) and returns 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.
Returns an array of keys given a value to be indexed. The number of returned keys must be stored into *nkeys .
Returns an array of keys given a value to be queried; that is,
is the value on the right-hand side of an indexable operator whose left-hand side is the indexed column.
is the strategy number of the operator within the operator class (see
will need to consult
to determine the data type of
and the key values that need to be extracted. The number of returned keys must be stored into
Returns TRUE if the indexed value satisfies the query operator with strategy number
(or may satisfy, if the operator is marked RECHECK in the operator class). The
array has the same length as the number of keys previously returned by
for this query. Each element of the
array is TRUE if the indexed value contains the corresponding query key, ie, if (check[i] == TRUE) the i-th key of the
result array is present in the indexed value. The original
datum (not the extracted key array!) is passed in case the
method needs to consult it.