GIN (Generalized Inverted Index) is great for “contains” queries on composite types like arrays and `jsonb` (e.g., `@>`, `?`). It indexes many-to-many relationships between keys and rows.
CREATE INDEX idx_events_payload ON events USING GIN (payload);
-- example query (jsonb contains)
SELECT * FROM events WHERE payload @> '{"type":"click"}';Expanding on the short answer — what usually matters in practice:
Here’s an additional example (building on the short answer):
CREATE INDEX idx_events_payload ON events USING GIN (payload);
-- example query (jsonb contains)
SELECT * FROM events WHERE payload @> '{"type":"click"}';