- **Description**: "Generalized Inverted Index". It maps "keys" (elements/lexemes) to a sorted list of TIDs (postings). A single heap row can result in multiple index entries if it contains multiple keys (e.g., an array or JSONB document).
- **Data Structure**:
- **Entry Tree**: A B-tree that maps unique keys to their matching records. Each leaf entry contains the key value and either an in-line **Posting List** or a pointer to a **Posting Tree**.
- **Posting List (`gin_posting_list`)**: For keys with low-to-medium frequency, a list of TIDs is stored directly in the entry. To save space, these TIDs are stored as **64-bit deltas** (the distance from the previous TID) and compressed using a **Varbyte encoding** scheme.
- **Posting Tree**: For high-frequency keys (e.g., the word "the" in a text search), the TIDs occupy their own dedicated B-Tree structure. In a Posting Tree leaf, the "data" is simply an array of TIDs, and the "keys" used for navigation are the TIDs themselves.
- **GIN Page Header (`gin_opaque`)**: Distinguishes between entry pages, posting list pages, and posting tree pages using flags like `GIN_LEAF`, `GIN_DATA`, and `GIN_COMPRESSED`.
- **Supported Operators**: `<@`, `@>`, `=`, `&&`.
- **Special Features**:
- **Pending List (`fastupdate`)**: New entries are initially stored in a flat, uncompressed "pending list" to speed up insertions. A background worker (or a large enough insert) eventually sorts and merges these into the main index via `gin_clean_pending_list`.
- **Metaphor**: The index at the back of a technical textbook. If a word appears on only a few pages, they are listed right there (Posting List). If it appears on a thousand pages, the index just gives you a reference to a separate, dedicated chapter just for that word (Posting Tree).