Storing semi‑structured data in a jsonb column is convenient, but without an index every query forces a full table scan. The common myth is that a generic GIN index on the whole column solves all cases; in reality, you should index the exact paths you query. An expression index on a specific key (or a combination of keys) lets PostgreSQL use the index efficiently while keeping the flexibility of JSONB.
-- Table with a JSONB payload
CREATE TABLE events (
id SERIAL PRIMARY KEY,
payload JSONB NOT NULL,
created_at TIMESTAMP DEFAULT now()