An operator class selects the operators and comparison semantics an index access method uses for a data type. With PostgreSQL GIN indexes on JSON data, different classes organize indexed information differently and support distinct data-access behavior. section 5.6.2
For JSONB GIN indexes, the available choices shown here are:
- The default class extracts keys, values, and array elements as separate index items. section 5.6.2
- jsonb_path_ops indexes paths from the document root to values and array elements. section 5.6.2
Choose jsonb_path_ops for a path-oriented GIN index
CREATE INDEX idx_pizza_orders_paths_ops_gin ON pizzeria.order_items USING GIN (pizza jsonb_path_ops); A containment query using @> uses this index through a Bitmap Index Scan and returns 563 rows in the demonstrated plan. section 5.6.2
Listing 5.16 Creating a default GIN index
CREATE INDEX idx_pizza_orders_gin ON pizzeria.order_items USING GIN(pizza);
Inspect the complete default GIN index definition before selecting an alternative operator class. section 5.6.2
