Bird
0
0

If your app needs to get product reviews by product ID and filter by rating, which access pattern fits best?

medium📝 query result Q5 of 15
DynamoDB - Access Patterns and Query Optimization
If your app needs to get product reviews by product ID and filter by rating, which access pattern fits best?
ANo keys, use Scan with filter
BPartition key on ProductID, sort key on Rating
CPartition key on ReviewID only
DPartition key on Rating, sort key on ProductID
Step-by-Step Solution
Solution:
  1. Step 1: Identify query needs

    App queries by product ID and filters by rating, so ProductID should be partition key and Rating as sort key.
  2. Step 2: Evaluate options

    Partition key on ProductID, sort key on Rating matches query pattern. Partition key on Rating, sort key on ProductID reverses keys, making queries inefficient. Partition key on ReviewID only lacks sort key for filtering. No keys, use Scan with filter is inefficient.
  3. Final Answer:

    Partition key on ProductID, sort key on Rating -> Option B
  4. Quick Check:

    Partition key = main query, sort key = filter [OK]
Quick Trick: Partition key for main query, sort key for filtering [OK]
Common Mistakes:
MISTAKES
  • Swapping partition and sort keys
  • Using only partition key without sort key
  • Relying on Scan instead of Query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes