GIN indexes for jsonb containment queries
The jsonb containment operator @> cannot use a B-tree. A GIN index makes it a bitmap scan instead of a full scan, the same 16,000 express documents without reading every row.
Problem
What you're actually looking at
The symptom as it shows up on a real server.
Querying jsonb with @> ("contains this key/value") has no B-tree answer, so PostgreSQL scans every row and tests each document. A GIN index indexes the jsonb contents and turns containment into an index lookup.
Meridian stores consignment documents as jsonb and looks up all express-service documents with payload @> '{"service":"express"}'. Unindexed, that is a full scan of every document.
Simple terms
The jsonb "contains" operator @> asks "does this document include this key and value?". A regular B-tree index cannot answer that, so PostgreSQL reads every row and tests each document one by one. A GIN index is built for exactly this job: it indexes the contents of the jsonb, turning a full scan into a quick lookup.
Full runbook for this incident
- The full identify checklist, the exact signals that tell you it's this incident
- Every diagnostic query; lab output is attached only to the steps we actually captured
- The resolution path and the pitfalls that make it worse
- Mitigation steps to stop it recurring, plus a verify-you're-done query
Card required. Cancel before day 7 and you are not charged.
More in this category
Other Indexing runbooks
Neighbouring incidents that share the same diagnostic surface.
Need the full procedure?
Pro runbooks finish the incident path
Free runbooks teach the shape. Pro opens the full step transcript, edge cases, and prevention depth.