diff --git a/source/core/index-compound.txt b/source/core/index-compound.txt index cc6b7f6187d..c7378979fc3 100644 --- a/source/core/index-compound.txt +++ b/source/core/index-compound.txt @@ -110,39 +110,41 @@ following: Prefixes -------- -Compound indexes support queries on any prefix of the index -fields. Index prefixes are the beginning subset of indexed fields. For -example, given the index ``{ a: 1, b: 1, c: 1 }``, both ``{ a: 1 }`` -and ``{ a: 1, b: 1 }`` are prefixes of the index. +Compound indexes support queries on any prefix of the index fields. +Index prefixes are the beginning subsets of indexed fields. For example, +``{ a: 1 }`` and ``{ a: 1, b: 1 }`` are both prefixes of the index +``{ a: 1, b: 1, c: 1 }``. -If you have a collection that has a compound index on ``{ a: 1, b: -1 }``, as well as an index that consists of the prefix of that index, -i.e. ``{ a: 1 }``, assuming none of the index has a sparse or unique -constraints, then you can drop the ``{ a: 1 }`` index. MongoDB will be -able to use the compound index in all of situations that it would have -used the ``{ a: 1 }`` index. +If an index is an exact prefix of a second index, and if neither index has +a sparse or unique constraint, then you can remove the first index. For +example, if you have an index on ``{ a: 1 }`` and also have a compound +index on ``{ a: 1, b: 1 }``, then you can remove the ``{ a: 1 }`` index. +MongoDB will use the ``{ a: 1, b: 1 }`` index in all of the situations +that it would have used the ``{ a: 1 }`` index. -For example, given the following index: +Given the following compound index: .. code-block:: javascript { "item": 1, "location": 1, "stock": 1 } -MongoDB **can** use this index to support queries that include: +MongoDB can use the index for queries on the following fields, which are +prefixes of the index: -- the ``item`` field, -- the ``item`` field *and* the ``location`` field, -- the ``item`` field *and* the ``location`` field *and* the - ``stock`` field, or -- only the ``item`` *and* ``stock`` fields; however, this index - would be less efficient than an index on only ``item`` and - ``stock``. +- ``item`` +- ``item``, ``location`` -MongoDB **cannot** use this index to support queries that include: +MongoDB **cannot** use the index for queries on the following fields, none +of which are prefixes of the index: -- only the ``location`` field, -- only the ``stock`` field, or -- only the ``location`` *and* ``stock`` fields. +- only on the ``location`` field +- only on the ``stock`` field +- only on the ``location`` and ``stock`` fields + +MongoDB **can** use the index to support a query on ``item`` and +``stock``, even though they are not a prefix. However, the index would not +be as efficient in supporting the query as would be an index on only +``item`` and ``stock``. Index Intersection ------------------