Bird
0
0

You want to create a GIN index on a JSONB column info in table users to optimize queries checking for existence of specific keys only, ignoring values. Which index operator class should you use?

hard📝 Application Q15 of 15
PostgreSQL - JSON and JSONB
You want to create a GIN index on a JSONB column info in table users to optimize queries checking for existence of specific keys only, ignoring values. Which index operator class should you use?
Ajsonb_ops
Bjsonb_path_ops
Cbtree_gin
Dhash_ops
Step-by-Step Solution
Solution:
  1. Step 1: Understand GIN operator classes for JSONB

    PostgreSQL provides two main operator classes for JSONB GIN indexes: jsonb_ops (default) indexes keys and values, and jsonb_path_ops indexes only keys for existence queries.
  2. Step 2: Choose operator class for key existence queries

    Since the goal is to optimize queries checking for key existence only, jsonb_path_ops is the best choice as it creates a smaller, faster index for this purpose.
  3. Final Answer:

    jsonb_path_ops -> Option B
  4. Quick Check:

    Key-only queries use jsonb_path_ops [OK]
Quick Trick: Use jsonb_path_ops for key-existence queries [OK]
Common Mistakes:
  • Using default jsonb_ops which indexes values too
  • Choosing unrelated operator classes like btree_gin
  • Confusing hash_ops with GIN operator classes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes