A developer is building an e-learning application. The application tracks student progress in an Amazon DynamoDB table named `CourseEnrollments`. The table uses `StudentID` as the partition key and `CourseID` as the sort key. The table contains attributes such as `CompletionPercentage` and `LastAccessedDate`. The developer needs to retrieve all progress records for a specific student where the `CompletionPercentage` is greater than . Which approach should the developer take to retrieve these records while minimizing the Read Capacity Units (RCUs) consumed?
- Perform a `Query` operation specifying the `StudentID` in the `KeyConditionExpression`, and use a `FilterExpression` to evaluate the `CompletionPercentage`.Cevap
- BPerform a `Scan` operation on the table, specifying both the `StudentID` and `CompletionPercentage` in the `FilterExpression`.
- CPerform a `Scan` operation on the table, specifying a `ProjectionExpression` to limit the returned attributes, and filter by `CompletionPercentage` in the application logic.
- DInitialize the DynamoDB client with hardcoded AWS access keys, and perform a `Scan` operation to retrieve the records.
Cevap
Perform a `Query` operation specifying the `StudentID` in the `KeyConditionExpression`, and use a `FilterExpression` to evaluate the `CompletionPercentage`.
The correct approach is to perform a `Query` operation specifying the partition key (`StudentID`) in the `KeyConditionExpression`, and then use a `FilterExpression` to narrow the results based on the `CompletionPercentage`. A `Query` operation only reads items that match the specified partition key, which significantly reduces the amount of data read and the number of Read Capacity Units (RCUs) consumed compared to a table scan. The `FilterExpression` is applied after the query reads the items from the partition but before returning the results to the application.
Adım Adım Çözüm
Anahtar Kavram
DynamoDB Query vs Scan efficiency and RCU optimization
Tahmini Süre:1m 30s