Bird
0
0

Which statement correctly creates the index and optimizes queries checking if an integer is present in the array?

hard📝 Application Q15 of 15
PostgreSQL - Indexing Strategies
You want to create a GIN index on a table orders with a column items that stores an array of integers. Which statement correctly creates the index and optimizes queries checking if an integer is present in the array?
ACREATE INDEX idx_items_gin ON orders USING GIN (items gin_int_ops);
BCREATE INDEX idx_items_gin ON orders USING GIN (items gin__int_ops);
CCREATE INDEX idx_items_gin ON orders USING GIN (items gin__intarray_ops);
DCREATE INDEX idx_items_gin ON orders USING GIN (items);
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct GIN index syntax for integer arrays

    For integer arrays, the default GIN index supports containment and membership queries without specifying operator classes.
  2. Step 2: Validate options

    Options B, C, and D use invalid operator class names like gin__int_ops or gin__intarray_ops, which do not exist in PostgreSQL.
  3. Final Answer:

    CREATE INDEX idx_items_gin ON orders USING GIN (items); -> Option D
  4. Quick Check:

    Default GIN index on array column = CREATE INDEX idx_items_gin ON orders USING GIN (items); [OK]
Quick Trick: Use default GIN index on array column without extra ops [OK]
Common Mistakes:
  • Using non-existent operator classes
  • Adding unnecessary syntax after column name
  • Confusing GIN with other index types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes