In DynamoDB, what is the main reason secondary indexes allow more flexible queries compared to querying only the primary key?
Think about how you can search by different columns without reading everything.
Secondary indexes let you query the table using different keys than the primary key, so you don't have to scan the whole table to find items.
Given a DynamoDB table with a Global Secondary Index on the attribute 'Category', what will this query return?
Query on GSI where Category = 'Books'
Remember what a GSI lets you do with attributes.
A GSI allows querying items based on the indexed attribute, here 'Category'. So the query returns all items with Category 'Books'.
Which of the following DynamoDB query commands correctly queries a Local Secondary Index named 'DateIndex' on the attribute 'Date'?
Remember that LSIs share the same partition key as the main table but have a different sort key.
LSIs require the partition key and the indexed sort key in the KeyConditionExpression. Option A correctly includes both.
You want to query a DynamoDB table by a non-primary key attribute that changes frequently and is not part of the primary key. Which index type should you use for best flexibility and why?
Think about which index type allows different partition keys and supports attribute updates.
Global Secondary Indexes allow different partition and sort keys and can index attributes that change frequently, making them more flexible for such queries.
You run this DynamoDB query on a Global Secondary Index named 'StatusIndex' but get an error:
query({ TableName: 'Tasks', IndexName: 'StatusIndex', KeyConditionExpression: 'Status = :s', ExpressionAttributeValues: { ':s': 'Pending' } })What is the most likely cause of the error?
Remember what must be included in the KeyConditionExpression when querying an index.
When querying a GSI, the KeyConditionExpression must include the GSI's partition key attribute. Using just 'Status' may be incorrect if 'Status' is not the partition key of the GSI.