You have a DynamoDB table with PartitionKey as the primary key. You run this query to get all items with PartitionKey = 'User#123'. What will be the output?
SELECT * FROM Table WHERE PartitionKey = 'User#123';Think about how DynamoDB handles queries on partition keys.
In DynamoDB, querying by PartitionKey returns all items with that key, regardless of SortKey values.
You want to design a DynamoDB table to store orders. You expect frequent queries by CustomerID and occasional queries by OrderDate. Which is the best choice for the partition key to optimize access patterns?
Think about which attribute is used most often in queries.
Choosing CustomerID as partition key optimizes frequent queries by customer. OrderDate can be a sort key or accessed via secondary indexes.
Which of the following DynamoDB query expressions correctly retrieves items with PartitionKey = 'User#456' and SortKey starting with 'Order#'?
Assume table has PartitionKey and SortKey attributes.Remember that KeyConditionExpression must use AND and can use begins_with for sort keys.
Option A correctly uses KeyConditionExpression with AND and begins_with for SortKey. Option A uses equality for SortKey which won't match prefixes. Option A uses FilterExpression which is less efficient. Option A uses OR which is invalid in KeyConditionExpression.
You have a DynamoDB table with primary key CustomerID and OrderID. You want to efficiently query orders by OrderStatus. What is the best way to optimize this access pattern?
Think about how to query efficiently by an attribute not in the primary key.
A GSI allows querying efficiently by attributes other than the primary key. Adding OrderStatus as sort key won't help if you want to query by OrderStatus alone. Scan is inefficient. Separate table adds complexity.
You run this DynamoDB query to get all orders for CustomerID = 'Cust#789' with OrderDate after '2023-01-01'. The query returns no results, but you know matching items exist. What is the likely cause?
QueryInput={
TableName: 'Orders',
KeyConditionExpression: 'CustomerID = :cid and OrderDate > :date',
ExpressionAttributeValues: { ':cid': 'Cust#789', ':date': '2023-01-01' }
}Check which attributes can be used in KeyConditionExpression.
KeyConditionExpression can only use partition key and sort key attributes. If OrderDate is not part of the key schema, it cannot be used there, causing no results.