MP056WARNINGFree

gin-index-on-jsonb-without-expression

What It Detects

A plain GIN index on a JSONB column only supports containment operators, not the common ->> extraction operator.

Why It's Dangerous

A GIN index with default jsonb_ops does NOT speed up queries using ->> or ->. Most ORMs generate WHERE metadata->>'key' = 'value' queries, which will still do a sequential scan. Use an expression B-tree index on the specific path instead.

Bad Example

CREATE INDEX idx_events_data ON events USING GIN (data);
-- Useless for: WHERE data->>'status' = 'active'

Good Example

-- For ->> queries, use expression B-tree:
CREATE INDEX idx_events_status ON events ((data->>'status'));
-- For @> containment, use jsonb_path_ops:
CREATE INDEX idx_events_data ON events USING GIN (data jsonb_path_ops);

Configuration

Disable this rule:

# .migrationpilotrc.yml
rules:
  MP056: false

Or change its severity:

# .migrationpilotrc.yml
rules:
  MP056:
    severity: warning