Bird
0
0

How can you combine a GIN index on full-text search with a filter on a category column to optimize queries?

hard📝 Application Q9 of 15
PostgreSQL - Full-Text Search
How can you combine a GIN index on full-text search with a filter on a category column to optimize queries?
ACreate a single BTREE index on both columns
BCreate two separate GIN indexes on to_tsvector and category
CCreate a BTREE index on to_tsvector and GIN on category
DCreate a composite index: GIN on to_tsvector and BTREE on category
Step-by-Step Solution
Solution:
  1. Step 1: Understand index types for each column

    Use GIN for full-text search column and BTREE for category filtering.
  2. Step 2: Create a composite index combining both

    PostgreSQL supports multicolumn indexes mixing GIN and BTREE.
  3. Final Answer:

    Create a composite index: GIN on to_tsvector and BTREE on category -> Option D
  4. Quick Check:

    Composite GIN + BTREE index optimizes both filters [OK]
Quick Trick: Combine GIN and BTREE in one index for text + filter [OK]
Common Mistakes:
  • Trying two GIN indexes on different columns
  • Using BTREE for full-text search column
  • Creating single BTREE index for both

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes