MongoDB 中的复合索引是否改进了多重匹配(而不是排序)?

does a compound index in MongoDB improve multified match (not sorting)?

文档对此似乎有点不清楚。

1) 它明确指出复合索引确实提高了多字段排序的性能(顺序和方向相关)。

2) 有一个短语让我认为它会 提高多场 MACH(sql 类比:其中 a=1 and b=2 and c <5)

https://docs.mongodb.org/v3.0/tutorial/optimize-query-performance-with-indexes-and-projections/

If a query searches multiple fields, create a compound index.

它没有提到排序。

那么对于像(其中 a=1 和 b=2 且 c<5)这样的查询,字段 a、b、c 上的复合索引是否比三个单字段索引的匹配性能更好?

是的,创建复合索引可以提高查询性能。

Create a Single-Key Index if All Queries Use the Same, Single Key

如果对于特定集合,您使用单个键进行匹配,例如 where a=1

Create Compound Indexes to Support Several Different Queries

如果您的查询使用一个或多个键,最好使用复合索引。

db.sample.createIndex( { "a": 1, "b": 1, "c":1 } )

可以只查询a,可以查询a结合b,也可以查询a、b、c。您可以使用 explain() 方法来了解您的查询使用的计划。

Index Intersection 也可能会优化查询的性能。它可以支持复合索引不支持的内容。