DELAPARRA
Index
Color
NL
Category: SQL

GIN index

Explained by Updated

What is GIN index?

GIN index: Generalised Inverted iNdex (Postgres) — for columns holding many values per row: arrays, JSONB, full-text. A GIN index, short for Generalised Inverted Index, is a PostgreSQL index for columns that hold many values per row. Arrays, JSONB documents and full-text search vectors are the typical cases. An inverted index maps each value to the rows that contain it, like the index at the back of a book. That makes queries such as "which documents contain this word" or "which products have this tag" fast, even across millions of rows.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about GIN index

What should you keep in mind with GIN index?

GIN indexes are slower to update than normal B-tree indexes, so they suit data that is read often and written less. For JSONB, the jsonb_path_ops variant is smaller and faster when you only need containment queries. MySQL has no direct equivalent; it offers FULLTEXT indexes for text and multi-valued indexes for JSON arrays instead.

What does an example of GIN index look like?

CREATE INDEX idx_docs_body ON docs USING gin (to_tsvector('english', body));

At a glance

CategorySQL
Explained by
Updated

More SQL terms

All terms starting with G

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.