DBS-C01 练习题

DBS-C01 题目讲解:强一致限制索引类型,也暴露题面缺口

DBS-C01 练习题讲解。答案 C。题目已明确每次查询同时提供 Customer ID 与 Invoice ID,符合 LSI 的同分区查询;LSI 需在新表创建时定义,再迁移数据。

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?

A. Add a global secondary index on Invoice ID to the existing table.
B. Add a local secondary index on Invoice ID to the existing table.
C. Create a new table with the same primary key and a local secondary index whose sort key is Invoice ID. Migrate the existing data and switch the application to the new table.
D. Use the partition key and a FilterExpression parameter with a filter on Invoice ID for all queries.

答案

答案 C。题目已明确每次查询同时提供 Customer ID 与 Invoice ID,符合 LSI 的同分区查询;LSI 需在新表创建时定义,再迁移数据。

拆题

  • 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 + INV9LSI 可在分区内查询
仅发票键只有 INV9LSI 不足
建索引创建新表时迁移与双写需规划

遇到同类题的判断顺序

  1. 确认访问模式:是否知道 Customer ID。
  2. 选择一致性:排除 GSI 强一致假设。
  3. 设计新表:建表时定义 LSI。
  4. 验证迁移:核对数据、写入和查询路径。
结论:不能把 LSI 当作任意新 partition key;本题 C 有明确前提。

参考资料

继续练这门考试

同一门考试的免费试练题都附这样的完整讲解,做完再看讲解。