54. You have a very large movies collection with the following indexes: > db.movies.getIndexes() [ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "video.movies" }, { "v" : 2, "key" : { "mpaaRating" : 1 }, "name" : "mpaaRating_q", "ns" : "video.movies", "partialFilterExpression" : { "viewerRating" : { "$gte" : 7 } } } ] Which of the following queries will be served by these indexes? Check all that apply:
题目选项
- A.db.movies.find({"mpaaRating": "PG"})
- B.db.movies.find({"viewerRating": 7, "mpaaRating": "G"})
- C.db.movies.find({"viewerRating": 7})
答案置信度:高
正确答案:B
解析语言:中文
部分索引只有在查询条件"包含 partialFilterExpression"时才会被使用:B 的 viewerRating:7 是 viewerRating:{$gte:7} 的子集,同时又带 mpaaRating 谓词,所以能命中 mpaaRating 这个部分索引。A 只查 mpaaRating,无法保证结果都落在 viewerRating>=7 的范围内(会漏掉 viewerRating<7 的文档),优化器不会用;C 只有 viewerRating 谓词,索引键 mpaaRating 上没有条件,只能全集合扫描。