Soru

Zorluk: OrtaData Store Operations with Amazon DynamoDB

A developer is building a warehouse inventory management application that uses an Amazon DynamoDB table. The table's partition key is WarehouseIDWarehouseID and the sort key is ItemIDItemID. The developer needs to retrieve all items belonging to a specific warehouse where the StockCountStockCount attribute is less than 1010. The table contains millions of items, but each individual warehouse has at most a few thousand items. Which approach should the developer use to retrieve the required items with the lowest latency and the most efficient Read Capacity Unit (RCURCU) consumption?

  1. Perform a `Query` operation specifying the WarehouseIDWarehouseID in the `KeyConditionExpression` and filtering the results using a `FilterExpression` for StockCountStockCount.Cevap
  2. B
    Perform a `Scan` operation on the table using a `FilterExpression` to match the WarehouseIDWarehouseID and StockCountStockCount.
  3. C
    Perform a `Scan` operation to retrieve all items in the table, and then filter out the items with a stock count greater than or equal to 1010 in the application memory.
  4. D
    Initialize the DynamoDB client with hardcoded IAM credentials in the application code, and perform a parallel `Scan` to quickly retrieve the data.

Cevap

Perform a Query operation specifying the WarehouseID in the KeyConditionExpression and filtering the results using a FilterExpression for StockCount.
The correct option is to perform a Query operation specifying the partition key (WarehouseIDWarehouseID) in the `KeyConditionExpression` and using a `FilterExpression` for the non-key attribute (StockCountStockCount). In DynamoDB, Query operations are optimized to search within a single partition key, avoiding full table scans and reducing both latency and Read Capacity Unit (RCU) consumption. The FilterExpression acts on the retrieved partition items before they are returned to the application, ensuring that only relevant items are sent over the network.

Adım Adım Çözüm

1
Analyze the table primary key structure and access pattern requirements.
The table has a composite primary key consisting of a partition key (WarehouseIDWarehouseID) and a sort key (ItemIDItemID). The query requires filtering by the partition key (WarehouseIDWarehouseID) and a non-key attribute (StockCountStockCount).
Identifying the partition key helps determine if a Query operation is possible, as a Query requires a specific partition key value.
2
Compare the efficiency of Query versus Scan operations.
A Query operation only reads items that match the specified partition key (WarehouseIDWarehouseID). A Scan operation reads every item in the entire table. Since we only want items for a specific warehouse, Query is much more efficient than Scan.
Using Query instead of Scan avoids reading millions of unrelated items, saving latency and RCU.
3
Determine the correct expressions to use in the Query operation.
Specify the partition key value in the `KeyConditionExpression` and specify the non-key attribute filter (StockCount<10StockCount < 10) in the `FilterExpression`.
The `KeyConditionExpression` is used to find the matching partition key, and the `FilterExpression` is used to filter the resulting items before they are returned to the application.

Anahtar Kavram

Choosing Query over Scan for partition key queries and filtering results using FilterExpressions to optimize performance and cost.
Bu soruyu puanla