Bird
0
0

You designed a DynamoDB table with primary key { PartitionKey: 'UserId' } but your app needs to query orders by OrderDate. What is the main problem and how to fix it?

medium📝 Debug Q14 of 15
DynamoDB - Access Patterns and Query Optimization
You designed a DynamoDB table with primary key { PartitionKey: 'UserId' } but your app needs to query orders by OrderDate. What is the main problem and how to fix it?
AProblem: Table size is too big; Fix: Use smaller partition keys
BProblem: Cannot query by OrderDate efficiently; Fix: Add OrderDate as sort key
CProblem: UserId is missing; Fix: Add UserId as partition key
DProblem: Query syntax error; Fix: Use Scan instead of Query
Step-by-Step Solution
Solution:
  1. Step 1: Identify the limitation of current key design

    With only partition key UserId, you cannot efficiently query by OrderDate alone.
  2. Step 2: Suggest design fix for access pattern

    Adding OrderDate as sort key allows queries by UserId and ordered by OrderDate efficiently.
  3. Final Answer:

    Problem: Cannot query by OrderDate efficiently; Fix: Add OrderDate as sort key -> Option B
  4. Quick Check:

    Sort key enables range queries by date [OK]
Quick Trick: Add sort key for secondary query attribute [OK]
Common Mistakes:
MISTAKES
  • Trying to query by non-key attribute without index
  • Using Scan instead of fixing key design
  • Ignoring need for composite key for multiple access patterns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes