Skip to main content

Overview

Note: This feature is currently a work in progress. Index building and maintenance are complete; scan implementation is partially implemented. Currently in the branches: SPR-1035-GIN-support-2 (build), SPR-1035-GIN-support-2-scan (scan)
GIN (Generalized Inverted Index) support enables efficient text similarity searches using trigram-based indexing. The implementation tokenizes text column values into 3-character trigrams and stores them in an inverted index structure, mapping each trigram to the rows containing it. The index schema stores entries as (column_position, token, internal_row_id) tuples, allowing multi-column GIN indexes where each column’s trigrams are distinguished by position. Currently, only gin_trgm_ops opclass is supported, enabling LIKE and ILIKE query operators.

Key Components

Index Building

Index Scanning (in-progress)

GIN Index Schema

Supported Operators


Data Flow

Index Building

Index Scanning (in-progress)


Implementation

Index Creation

GIN index creation validates opclass before persisting metadata:

Trigram Extraction (Build)

Unpacks PostgreSQL packed trigram integers to 3-byte strings:

Full Index Build and reconciliation

Iterates table rows and inserts trigram tuples:

Incremental Maintenance

Mutation handler distinguishes GIN from BTree indexes:

Schema Creation

GIN index schema defines three key columns:

Trigram Extraction (Query)

Invokes opclass extractQuery for search pattern:

GIN Iterator (in-progress)

Deduplicates rows and resolves physical location:

FDW Query Routing (in-progress)

Routes LIKE/ILIKE operators to GIN index:

Path to Completion

The following work remains to complete GIN index support:
  1. Scan Implementation - The GINSecondary iterator currently iterates all index entries. It needs to:
    • Filter entries to only those matching the extracted query tokens
    • Implement proper token intersection logic (all query trigrams must match)
  2. Query Optimization - The FDW currently uses hardcoded gin_trgm_ops and collation. This should be derived from the index metadata.
  3. Testing - End-to-end testing of LIKE/ILIKE queries using GIN indexes.