Given a DynamoDB table with a composite sort key in the format TYPE#ID, which query will return all items where the sort key starts with ORDER# for a given partition key USER#123?
PartitionKey = 'USER#123' SortKey begins with 'ORDER#'
Use begins_with in the KeyConditionExpression to filter sort keys by prefix.
Option C correctly uses begins_with in the KeyConditionExpression to query items with sort keys starting with ORDER# for the given partition key.
Option C looks for exact match, which won't return all prefixed items.
Option C uses FilterExpression, which filters after fetching all partition key items, less efficient.
Option C uses a greater than comparison, which may return unwanted items.
Why do we use a composite sort key like TYPE#ID in DynamoDB tables?
Think about how combining values helps with queries.
Composite sort keys combine multiple pieces of information into one attribute, allowing queries to filter and sort efficiently by parts of the key.
Options A, B, and D do not describe the purpose of composite sort keys.
Which of the following DynamoDB query snippets correctly retrieves items with partition key USER#456 and sort keys between ORDER#100 and ORDER#200 inclusive?
Use BETWEEN in KeyConditionExpression for inclusive range queries.
Option B uses BETWEEN in the KeyConditionExpression which is the correct syntax for inclusive range queries on sort keys.
Option B uses multiple conditions which is invalid in KeyConditionExpression.
Option B uses FilterExpression which filters after fetching all partition key items, less efficient.
Option B uses exclusive range operators which exclude boundary values.
A developer queries a DynamoDB table with partition key USER#789 and sort key prefix INVOICE# using this expression:
KeyConditionExpression: 'PartitionKey = :pk AND SortKey = :prefix', ExpressionAttributeValues: { ':pk': 'USER#789', ':prefix': 'INVOICE#' }Why does this query return no results even though items with sort keys like INVOICE#001 exist?
Think about how equality works versus prefix matching.
The query uses SortKey = :prefix which looks for an exact match to 'INVOICE#'. Since items have sort keys like 'INVOICE#001', they do not match exactly.
Option A is incorrect because the partition key is assumed correct.
Option A is incorrect because attribute names are correct.
Option A is false; DynamoDB supports querying by sort key.
You have a DynamoDB table where the sort key combines type and id like TYPE#ID. You want to efficiently query all items of types ORDER and INVOICE for partition key USER#999. Which approach is best?
Consider query efficiency and DynamoDB limitations on OR conditions in KeyConditionExpression.
Option D is best because DynamoDB does not support OR in KeyConditionExpression, so separate queries with begins_with are efficient and precise.
Option D uses FilterExpression with OR, which filters after fetching all partition key items, less efficient.
Option D scans the entire table, very inefficient.
Option D requires schema changes and may not be feasible.