Bird
0
0

Which secondary index should you create and how?

hard📝 Application Q15 of 15
AWS - DynamoDB
You have a DynamoDB table with a partition key UserId and sort key OrderDate. You want to efficiently query all orders by Status and sort them by OrderAmount. Which secondary index should you create and how?
ACreate a Global Secondary Index with partition key <code>Status</code> and sort key <code>OrderAmount</code>.
BCreate a Local Secondary Index with partition key <code>UserId</code> and sort key <code>Status</code>.
CCreate a Global Secondary Index with partition key <code>UserId</code> and sort key <code>Status</code>.
DCreate a Local Secondary Index with partition key <code>Status</code> and sort key <code>OrderAmount</code>.
Step-by-Step Solution
Solution:
  1. Step 1: Identify query requirements

    You want to query by Status (different from main partition key) and sort by OrderAmount.
  2. Step 2: Choose index type and keys

    Since Status is different from main partition key, use a Global Secondary Index with Status as partition key and OrderAmount as sort key.
  3. Final Answer:

    Create a Global Secondary Index with partition key Status and sort key OrderAmount. -> Option A
  4. Quick Check:

    GSI allows different partition and sort keys [OK]
Quick Trick: Use GSI when partition key differs from main table [OK]
Common Mistakes:
  • Trying to use LSI with different partition key
  • Swapping partition and sort keys incorrectly
  • Choosing wrong index type for query pattern

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More AWS Quizzes