DBS-C01 免费试练题 · 考证匠讲解
题目
A company's ecommerce website uses Amazon DynamoDB for purchase orders. Each order is made up of a Customer ID and an Order ID. The DynamoDB table uses the Customer ID as the partition key and the Order ID as the sort key. To meet a new requirement, the company also wants the ability to query the table by using a third attribute named Invoice ID. Each query provides a Customer ID and an Invoice ID, and the result must be strongly consistent. A database specialist must provide this capability with optimal performance and minimal overhead. What should the database administrator do to meet these requirements?
答案
拆题
- GSI 查询只提供最终一致性,LSI 可以请求强一致读取,但保留原 partition key。
- LSI 只能建表时定义,不能往现有表追加;因此原题库选择重建。
- 已知 Customer ID 是本题的必要访问条件:LSI 共享表分区键,在同一个客户分区中使用 Invoice ID 排序键查询,并设置 ConsistentRead=true。
每个选项为什么对、为什么错
- A:GSI 可用 Invoice ID 作分区键,但不支持所需强一致读取。
- B:LSI 本身支持强一致,但不能追加到已存在表。
- C(正确):创建新表时定义 LSI,使用 Customer ID 为分区键、Invoice ID 为索引排序键,再迁移旧数据并切换应用。这样可强一致查询;现有表不能原地追加 LSI,也不能把“恢复快照”当作任意增加索引的操作。
- D:FilterExpression 在读取后过滤,并不把 Invoice ID 变为有效索引键,读量和性能不理想。
放到具体场景里
教学例子:已知客户 C42,按 CustomerID=C42 且 InvoiceID=INV9 查询 LSI 并设置 ConsistentRead=true。如果只有 INV9,没有 C42,LSI 无法解决全表按发票找订单;需另设计以发票为主键的数据结构和一致性维护,而不是强行宣称 C 满足全部需求。
| 检查对象 | 本例条件或动作 | 结果与边界 |
|---|---|---|
| 已知客户键 | C42 + INV9 | LSI 可在分区内查询 |
| 仅发票键 | 只有 INV9 | LSI 不足 |
| 建索引 | 创建新表时 | 迁移与双写需规划 |
遇到同类题的判断顺序
- 确认访问模式:是否知道 Customer ID。
- 选择一致性:排除 GSI 强一致假设。
- 设计新表:建表时定义 LSI。
- 验证迁移:核对数据、写入和查询路径。
参考资料
继续练这门考试
同一门考试的免费试练题都附这样的完整讲解,做完再看讲解。
