-
Notifications
You must be signed in to change notification settings - Fork 1.7k
WRITING-904 updates to compound indexes per audit #2137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be here. Belongs where it used to be. |
||
|
||
Index Intersection | ||
------------------ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you moved the wrong paragraph. That's probably my fault -- I probably commented on an outdated commit, which skewed the line. This needs to go down, so organizationally, we want:
Prefixes
def of prefixes of indexes
examples of queries supported by index
examples of queries not supported by index
Can get rid of other indexes that are prefixes.