#819

Speed up lookups inside a JSONB field

In events there's a payload column of type JSONB, and a common filter looks like «find events where payload contains the key plan with value pro». On big tables without the right index that's a full scan. The pattern calls for a GIN inverted index — it efficiently answers «does this JSONB contain the given fragment». For containment queries the optimal operator class is jsonb_path_ops: smaller and faster than the default, because it stores a hash of the entire path rather than every key separately. Build a GIN index named events_payload_gin_idx on events.payload using the jsonb_path_ops operator class specifically.

Your query result will appear here