A developer is building a user management module for a web application. The user data is stored in an Amazon DynamoDB table where the partition key is . The developer needs to support two new query patterns: retrieving all users in a specific city () sorted by their registration date (), and retrieving a user's details by their unique email address (). The solution must optimize read latency and minimize consumed capacity. Which two actions should the developer take to meet these requirements?
- Create a global secondary index (GSI) with as the partition key and as the sort key.Cevap
- Create a global secondary index (GSI) with as the partition key.Cevap
- CCreate a local secondary index (LSI) with as the sort key.
- DPerform a Scan operation on the base table using a FilterExpression on the attribute.
- EPerform a Scan operation on the base table filtering by the attribute, and then sort the results in the application code.
Cevap
Create a global secondary index (GSI) with City as the partition key and RegistrationDate as the sort key, and create a GSI with Email as the partition key.
To support queries on attributes other than the base table partition key without executing full scans, the developer must use Global Secondary Indexes (GSIs). A GSI with City as the partition key and RegistrationDate as the sort key directly satisfies the city-based lookup and sorts the data efficiently. A GSI with Email as the partition key allows lookups by email without needing the UserID.
Adım Adım Çözüm
Anahtar Kavram
Using Global Secondary Indexes (GSIs) to support query patterns that use partition keys different from the base table primary key, avoiding expensive Scan operations.