Bird
0
0

You want to speed up full-text search on a JSONB column data containing text under key description. How do you create a GIN index for this?

hard📝 Application Q8 of 15
PostgreSQL - Full-Text Search
You want to speed up full-text search on a JSONB column data containing text under key description. How do you create a GIN index for this?
ACREATE INDEX idx_data_desc ON items USING BTREE (data->>'description');
BCREATE INDEX idx_data_desc ON items USING GIN (data);
CCREATE INDEX idx_data_desc ON items USING GIN (to_tsvector('english', data->>'description'));
DCREATE INDEX idx_data_desc ON items USING HASH (to_tsvector('english', data));
Step-by-Step Solution
Solution:
  1. Step 1: Extract text from JSONB

    Use data->>'description' to get text from JSONB.
  2. Step 2: Create GIN index on to_tsvector of extracted text

    Apply to_tsvector with 'english' config for full-text search.
  3. Final Answer:

    CREATE INDEX idx_data_desc ON items USING GIN (to_tsvector('english', data->>'description')); -> Option C
  4. Quick Check:

    GIN index on to_tsvector of JSONB text = CREATE INDEX idx_data_desc ON items USING GIN (to_tsvector('english', data->>'description')); [OK]
Quick Trick: Extract JSONB text then apply to_tsvector for GIN index [OK]
Common Mistakes:
  • Indexing JSONB column directly without to_tsvector
  • Using BTREE or HASH for full-text search
  • Applying to_tsvector on entire JSONB

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes