5. You want to optimize a Supabase table products that is frequently searched by category and price. Which index strategy is best to improve query speed without slowing inserts too much?
hard
A. Create no indexes to keep inserts fast
B. Create a composite index on (category, price)
C. Create an index only on price
D. Create separate indexes on category and price
Solution
Step 1: Understand composite vs separate indexes
A composite index on (category, price) helps queries filtering both columns efficiently.
Step 2: Consider insert performance
One composite index is faster to update than two separate indexes, balancing speed and insert cost.
Step 3: Evaluate options
Create a composite index on (category, price) optimizes queries on both columns with minimal insert slowdown.
Final Answer:
Create a composite index on (category, price) -> Option B
Quick Check:
Composite index = faster multi-column queries [OK]
Hint: Use composite indexes for multi-column searches [OK]
Common Mistakes:
Creating too many separate indexes
Indexing only one column when both are searched
Avoiding indexes and hurting query speed
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.