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, query is the value on the
right-hand side of an indexable operator whose left-hand
side is the indexed column. n is
the strategy number of the operator within the operator
class (see Section
extractQuery will need to consult
n to determine the data type of
query and the key values that need
to be extracted. The number of returned keys must be stored
into *nkeys. If number of keys is
equal to zero then
extractQuery should store 0 or -1 into
*nkeys. 0 means that any row
matches the query and sequence
scan should be produced. -1 means nothing can satisfy
query. Choice of value should be
based on semantics meaning of operation with given strategy
Returns TRUE if the indexed value satisfies the query
operator with strategy number n
(or would satisfy, if the operator is marked RECHECK in the
operator class). The check array
has the same length as the number of keys previously
this query. Each element of the check array is TRUE if the indexed value
contains the corresponding query key, ie, if (check[i] ==
TRUE) the i-th key of the
extractQuery result array is present in
the indexed value. The original query datum (not the extracted key array!)
is passed in case the
consistent method needs to consult
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.