MongoDB中唯一索引的优势 [英] Advantage of a unique index in MongoDB

查看:199
本文介绍了MongoDB中唯一索引的优势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试搜索Mongo文档,但实际上找不到关于唯一索引的查询是否比对非唯一索引(给定数据)的查询要快的任何细节

I've tried to search through Mongo documentation, but can't really find any details on whether queries on unique indexes will be faster than queries on non-unique indexes (given the same data)

因此,我知道独特的索引将具有很高的选择性和良好的性能.但是,给定两个字段的串联是唯一的,非唯一复合索引的执行速度是否会比唯一复合索引慢?

So I understand that a unique index will have high selectivity and good performance. But, given two fields whose concatenation is unique, would a non-unique compound index perform slower than a unique compound index?

我假设唯一索引会减慢插入速度,因为必须验证唯一性.但是,如果有独特索引的读取性能提高,真的值得吗?

I am assuming that unique indexes can slow down inserts as the uniqueness must be verified. But is the read performance improvement of a unique index, if any, really worth it?

推荐答案

对源树的快速grep似乎表明唯一索引仅用于插入,因此查询之间不应有任何性能上的好处或损害返回一个文档,无论索引是否唯一.

A quick grep of the source tree seems to indicate that unique indexes are only used on insert, so there shouldn't be any performance benefit or detriment between a query that returns one document, whether the index is unique or not.

MongoDB索引被实现为btree,因此无论索引是否唯一,它们执行任何不同的操作都没有逻辑上的意义.

MongoDB indexes are implemented as btrees, so it wouldn't make any logical sense for them to perform any differently whether the index is unique or not.

这篇关于MongoDB中唯一索引的优势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆