创建新复合索引与添加到现有复合索引的权衡是什么?
What are the tradeoffs of creating a new compound index versus adding to an existing?
我正在按字段 a
、b
和 c
进行查询,并具有此索引:
{a: 1, b: 1, c: 1}
我要在 a
上添加一个新查询,按 d
desc 排序。我应该将索引更改为:
{a: 1, b: 1, c: 1, d: -1}
或者我应该添加第二个索引:
{a: 1, d: -1}
在这种情况下,更改索引不起作用(请参阅 http://docs.mongodb.org/manual/tutorial/sort-results-with-indexes/#sort-and-non-prefix-subset-of-an-index)。
在查询非顺序复合索引字段的一般情况下,虽然创建索引总是占用更多的内存,但性能会更好:
"However, the index would not be as efficient in supporting the query as would be an index on only item and stock."
http://docs.mongodb.org/manual/core/index-compound/
我正在按字段 a
、b
和 c
进行查询,并具有此索引:
{a: 1, b: 1, c: 1}
我要在 a
上添加一个新查询,按 d
desc 排序。我应该将索引更改为:
{a: 1, b: 1, c: 1, d: -1}
或者我应该添加第二个索引:
{a: 1, d: -1}
在这种情况下,更改索引不起作用(请参阅 http://docs.mongodb.org/manual/tutorial/sort-results-with-indexes/#sort-and-non-prefix-subset-of-an-index)。
在查询非顺序复合索引字段的一般情况下,虽然创建索引总是占用更多的内存,但性能会更好:
"However, the index would not be as efficient in supporting the query as would be an index on only item and stock." http://docs.mongodb.org/manual/core/index-compound/