简体   繁体   English

MongoDB的多个复合索引会影响性能吗?

[英]MongoDB multiple compound indexing will affect performance?

Is creating multiple compound indexes for serving various types of queries is better? 创建多个复合索引以服务各种类型的查询是否更好? or 要么
Is it better to use a single compound index in a way that supports multiple queries(which is hard to analysis and construct, since there are many number of queries). 最好以支持多个查询的方式使用单个复合索引(由于存在许多查询,因此难以分析和构造)。
My basic question is " Does creating multiple compound indexes will slow down read/write operations? " 我的基本问题是“ 创建多个复合索引是否会减慢读/写操作的速度?

Please suggest me a solution. 请给我建议一个解决方案。

There isn't any answer that fits all cases, but in general adding the right indexes will give you better performance. 没有适合所有情况的答案,但总的来说,添加正确的索引将为您提供更好的性能。 You will have less reads when accessing data. 访问数据时,读取次数会减少。 Calculating the index will cost you some performance, however if they are correct and used your db will perform better afterwards. 计算索引将使您付出一些性能,但是如果索引正确并被使用,则之后的数据库性能会更好。 Start with monitoring: mongodb monitoring docs 从监视开始: mongodb监视文档

Indices will slow down writes but speed up reads. 索引会减慢写入速度,但会加快读取速度。 A high read to write ratio warrants one or more indices on commonly fetched fields (keys). 高的读写比保证了在通常获取的字段(键)上有一个或多个索引。 For example our current system sees 25 writes to 20,000 reads (tps) so indices are beneficial to counter the wide margin. 例如,我们当前的系统看到25次写入到20,000次读取(tps),因此索引有利于抵消较大的利润。 That being said, be mindful of retaining the mongo write lock as short as possible. 话虽如此,请注意将mongo写锁保持得尽可能短。

MongoDB uses a readers-writer 1 lock that allows concurrent reads access to a database but gives exclusive access to a single write operation. MongoDB使用读取器-写入器1锁,该锁允许对数据库的并发读取访问,但对单个写入操作具有独占访问权限。 mongodb docs mongodb文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM