PostgreSQL 9.5alpha1 Documentation
Prev | Up | Chapter 61. BRIN Indexes | Next

# 61.3. Extensibility

The BRIN interface has a high level of abstraction, requiring the access method implementer only to implement the semantics of the data type being accessed. The BRIN layer itself takes care of concurrency, logging and searching the index structure.

All it takes to get a BRIN access method working is to implement a few user-defined methods, which define the behavior of summary values stored in the index and the way they interact with scan keys. In short, BRIN combines extensibility with generality, code reuse, and a clean interface.

There are four methods that an operator class for BRIN must provide:

`BrinOpcInfo *opcInfo(Oid type_oid)`

  Returns internal information about the indexed columns' summary data. The return value must point to a palloc'd `BrinOpcInfo`, which has this definition:

      typedef struct BrinOpcInfo
      {
          /* Number of columns stored in an index column of this opclass */
          uint16      oi_nstored;

          /* Opaque pointer for the opclass' private use */
          void       *oi_opaque;

          /* Type cache entries of the stored columns */
          TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];
      } BrinOpcInfo;

  `BrinOpcInfo`.`oi_opaque` can be used by the operator class routines to pass information between support procedures during an index scan.

`bool consistent(BrinDesc *bdesc, BrinValues *column, ScanKey key)`

  Returns whether the ScanKey is consistent with the given indexed values for a range. The attribute number to use is passed as part of the scan key.

`bool addValue(BrinDesc *bdesc, BrinValues *column, Datum newval, bool isnull)`

  Given an index tuple and an indexed value, modifies the indicated attribute of the tuple so that it additionally represents the new value. If any modification was done to the tuple, `true` is returned.

`bool unionTuples(BrinDesc *bdesc, BrinValues *a, BrinValues *b)`

  Consolidates two index tuples. Given two index tuples, modifies the indicated attribute of the first of them so that it represents both tuples. The second tuple is not modified.

To implement these methods in a generic way, the operator class defines its own internal support functions. (For instance, "min/max" operator classes implements support functions for the four inequality operators for the data type.) Additionally, the operator class must supply appropriate operator entries, to enable the optimizer to use the index when those operators are used in queries.

Prev | Home | Next
Built-in Operator Classes | Up | Writing A TABLESAMPLE Sampling Method