Bird
0
0

You want to speed up queries that find all text rows similar to a search term using trigram similarity. Which GiST index creation is best?

hard📝 Application Q8 of 15
PostgreSQL - Indexing Strategies
You want to speed up queries that find all text rows similar to a search term using trigram similarity. Which GiST index creation is best?
ACREATE INDEX idx_text_hash ON texts USING hash (text_column);
BCREATE INDEX idx_text_btree ON texts USING btree (text_column);
CCREATE INDEX idx_text_gist ON texts USING gist (text_column gist_trgm_ops);
DCREATE INDEX idx_text_gin ON texts USING gin (text_column gin_trgm_ops);
Step-by-Step Solution
Solution:
  1. Step 1: Identify index type for trigram similarity

    GiST with gist_trgm_ops supports trigram similarity searches efficiently.
  2. Step 2: Compare other index types

    B-tree does not support trigram similarity. GIN with gin_trgm_ops is also valid but question asks for GiST specifically. Hash indexes do not support similarity.
  3. Final Answer:

    CREATE INDEX idx_text_gist ON texts USING gist (text_column gist_trgm_ops); -> Option C
  4. Quick Check:

    GiST + gist_trgm_ops = trigram similarity index [OK]
Quick Trick: Use gist_trgm_ops with GiST for trigram similarity [OK]
Common Mistakes:
  • Choosing GIN instead of GiST when GiST is required
  • Using B-tree for similarity searches
  • Using hash index which doesn't support similarity

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes