MongoDB 如何管理二级索引扫描?

发布于 2024-09-25 10:05:37 字数 168 浏览 1 评论 0原文

默认情况下,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

庆幸我还是我 2024-10-02 10:05:37

每个分片都有自己的索引(仅包含该分片中的文档),它们将被并行访问(每个分片读取自己的本地索引分片)并合并结果。这不是随机读取,而是多个并行索引读取。从单个分片的角度来看,这看起来就像普通的索引访问。

这种索引分片也是二级索引在分片环境下无法唯一的原因(没有单一的全局索引可以保证唯一性)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文