CertGrid CertGrid
Hands-on Lab·PostgreSQL

PostgreSQL Index Types and Index Selection

A partial index is a fifth the size and answers its query in 0.285 ms. A GIN index on the same table produces no improvement at all - 15.9 ms against 16.5 ms - because the predicate matches a third of the rows.

Performance Guide 34 of 47 Advanced

GIN is the index type for containment queries on jsonb and arrays. It cannot help extraction predicates like payload->>'tier' = 'gold', which need a btree on the expression instead.

Every command on this page ran on db-a01.
Server NameIP AddressOSRolesCPURAMHDD
db-a01192.168.0.81Ubuntu 26.04 LTSPrimary / Source / Replica Set Member 12 Core4 GB50 GB

This guide includes

Use this when choosing an index type rather than reaching for a btree by reflex. This matters because a partial index can be a fifth the size and still answer its query faster - and a GIN index can turn out not to help at all.

Before you start

  1. Index only the rows you query

  2. Measure what the partial index does

  3. Add a GIN index, and find it does not help

Official sources