Bird
0
0

In a DynamoDB single-table design, if items have PK = 'CUSTOMER#456' and SK values like 'INVOICE#2023-05' and 'INVOICE#2023-06', what will a query with KeyConditionExpression: PK = :pk AND begins_with(SK, :skPrefix) return when :pk = 'CUSTOMER#456' and :skPrefix = 'INVOICE#2023-'?

medium📝 query result Q4 of 15
DynamoDB - Access Patterns and Query Optimization
In a DynamoDB single-table design, if items have PK = 'CUSTOMER#456' and SK values like 'INVOICE#2023-05' and 'INVOICE#2023-06', what will a query with KeyConditionExpression: PK = :pk AND begins_with(SK, :skPrefix) return when :pk = 'CUSTOMER#456' and :skPrefix = 'INVOICE#2023-'?
AOnly the invoice with SK exactly matching 'INVOICE#2023-'
BAll invoices for customer 456 from 2023, including May and June
CAll items with PK 'CUSTOMER#456' regardless of SK
DNo items, because begins_with cannot be used with SK
Step-by-Step Solution
Solution:
  1. Step 1: Understand begins_with on SK

    The begins_with function filters sort keys starting with the given prefix.
  2. Step 2: Apply to given SK values

    SK values 'INVOICE#2023-05' and 'INVOICE#2023-06' both start with 'INVOICE#2023-'.
  3. Final Answer:

    All invoices for customer 456 from 2023, including May and June -> Option B
  4. Quick Check:

    Check SK prefixes match [OK]
Quick Trick: begins_with matches all SK starting with prefix [OK]
Common Mistakes:
MISTAKES
  • Assuming begins_with matches exact SK only
  • Ignoring the prefix filtering on SK
  • Thinking begins_with cannot be used with sort keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes