![[assets/str_idx_gin.png|256]] - **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 where each leaf node contains a key and either a **Posting List** or a pointer to a **Posting Tree**. - **Posting List**: For keys with few occurrences, a list of TIDs is stored directly in the entry tree, compressed using a varbyte algorithm (`GIN_COMPRESSED`). - **Posting Tree**: For high-cardinality keys, TIDs are stored in a separate B-tree structure where the keys are the TIDs themselves. - **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).