A developer is designing a corporate training portal that tracks student progress using an Amazon DynamoDB table. The base table key schema consists of as the partition key and as the sort key. The application must support two primary query patterns: retrieving all courses completed by a specific user within a specified date range sorted by completion date, and retrieving all users who have completed a specific course. Which two strategies should the developer implement to meet these requirements with the most efficient database operations?
- Create a Local Secondary Index (LSI) with as the partition key and as the sort key.Cevap
- Create a Global Secondary Index (GSI) with as the partition key and as the sort key.Cevap
- CPerform a Scan operation on the base table using a FilterExpression on to identify all users who completed the course.
- DPerform a Scan operation on the base table using a FilterExpression on to filter the user's courses.
- EInitialize the DynamoDB client in the application code by hardcoding static AWS Access Keys to authenticate the query operations.
Cevap
Create a Local Secondary Index (LSI) with UserID as the partition key and CompletionDate as the sort key, and create a Global Secondary Index (GSI) with CourseID as the partition key and UserID as the sort key.
To support retrieving all courses completed by a specific user within a date range, the developer should create a Local Secondary Index (LSI) with the user ID as the partition key and the completion date as the sort key. This enables key-based Query operations with sorting on the date. To find all users who completed a specific course, a Global Secondary Index (GSI) with the course ID as the partition key is required because queries must look up records using an attribute other than the base table's partition key.
Adım Adım Çözüm
Anahtar Kavram
DynamoDB Secondary Indexes (LSI vs GSI) and Query Optimization