MongoDB 如何管理二级索引扫描?
默认情况下,MongoDB 在文档中的 _id 键上创建索引。但是当我确保附加索引(像 MySQL 中的 InnoDB 中的辅助索引?)并在之后查询它时,引擎会扫描它,然后选择性扫描 _id 索引来获取文档偏移量?
我很困惑,因为当分片到来时,我是对的,每个块都有自己的索引,并且每个查询会有很多随机读取?
By default MongoDB creates index on _id key in document. But when I ensure additional index (secondary like in InnoDB from MySQL?) and query it after, engine scans it and then selective scan _id index to get documments offsets?
I'm confused because when sharding comes it I'm right every chunk have own indexes and there will be many random reads per query?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个分片都有自己的索引(仅包含该分片中的文档),它们将被并行访问(每个分片读取自己的本地索引分片)并合并结果。这不是随机读取,而是多个并行索引读取。从单个分片的角度来看,这看起来就像普通的索引访问。
这种索引分片也是二级索引在分片环境下无法唯一的原因(没有单一的全局索引可以保证唯一性)。
Every shard will have its own index (containing just the documents in this shard), they will be accessed in parallel (every shard reads its own local index shard) and the results merged. This is not random reads, but multiple parallel index reads. From the perspective of a single shard, this looks just like a normal index access.
This index sharding is also the reason why secondary indexes cannot be unique in a sharding environment (there is no single global index that could ensure uniqueness).