PostgreSQL 8.2.10 Documentation
Prev | Fast Backward | Chapter 51. GIN Indexes | Fast Forward | Next

# 51.2. Extensibility

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:

int compare(Datum a, Datum b)

  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.

Datum* extractValue(Datum inputValue, uint32 *nkeys)

  Returns an array of keys given a value to be indexed. The number of returned keys must be stored into `*nkeys`.

Datum* extractQuery(Datum query, uint32 *nkeys, StrategyNumber n)

  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 33.14.2). Often, `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`.

bool consistent(bool check[], StrategyNumber n, Datum query)

  Returns TRUE if the indexed value satisfies the query operator with strategy number `n` (or may satisfy, if the operator is marked RECHECK in the operator class). The `check` array has the same length as the number of keys previously returned by `extractQuery` for 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 it.

Prev | Home | Next
Introduction | Up | Implementation