1Consider a collection called reviews which consists of documents with the following fields: product_name (string) this field is not unique as there are several products with the same prefix product_id (ObjectId) this field has several duplicates as popular products get more reviews review (string) almost unique across all documents, only a few duplicate values reviewer_id (string) this field has a few values that are in many document for frequent reviewers, these are the exception as most people only give a few reviews rating (integer) this field contains a value from 1 to 5 reviewed_at (Timestamp) almost unique across all documents, only a few duplicate values _id (ObjectId) automatically created on insert, unique across all documents Which of the following shard keys below is the best of those listed to support queries on the reviews collection? Choose the best answer:
题目选项
- A.{ product_id: 1, _id: 1}
- B.{ reviewed_at: 1, product_name: 1}
- C.{ reviewer_id: 1, reviewed_at: 1}
答案置信度:低
正确答案:C
解析语言:中文
这道题的考生答案存在分歧(DBA 卷记 {reviewed_at, product_name}、DEV 卷记 {reviewer_id, reviewed_at}),我按分片键三要素判定:reviewer_id 大多数情况下取值不重复(只有少数高频评论者是例外),基数高、频率低且不是单调递增,再加 reviewed_at 作后缀打破重复,整体最均衡,故取 C。B 的致命点是 reviewed_at 为单调递增的时间戳,新评论会持续落到最后一个 chunk 形成写热点;A 的 product_id 对热门商品频率极高,容易产生无法分裂的 jumbo chunk。