-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-41986: multikey indexes #140
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
Merged
rustagir
merged 6 commits into
mongodb:php-standardization
from
rustagir:DOCSP-41986-multikey-indexes
Sep 13, 2024
Merged
Changes from 4 commits
Commits
Show all changes
6 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
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
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
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
.. _php-multikey-index: | ||
|
||
================ | ||
Multikey Indexes | ||
================ | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 2 | ||
:class: singlecol | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: index, query, optimization, efficiency | ||
|
||
Overview | ||
-------- | ||
|
||
**Multikey indexes** are indexes that improve the performance of queries | ||
on array-valued fields. You can create a multikey index on a collection | ||
by using the ``MongoDB\Collection::createIndex()`` method and the same | ||
syntax that you use to create :ref:`single field | ||
<php-single-field-index>` or compound indexes. | ||
|
||
Sample Data | ||
~~~~~~~~~~~ | ||
|
||
The examples in this guide use the ``movies`` collection in the | ||
``sample_mflix`` database from the :atlas:`Atlas sample datasets | ||
</sample-data>`. To learn how to create a free MongoDB Atlas cluster and | ||
load the sample datasets, see the :atlas:`Get Started with Atlas | ||
</getting-started>` guide. | ||
|
||
Create a Multikey Index | ||
----------------------- | ||
|
||
Use the ``MongoDB\Collection::createIndex()`` method to create a | ||
multikey index. The following example creates an index in ascending | ||
order on the array-valued ``cast`` field: | ||
|
||
.. literalinclude:: /includes/indexes/indexes.php | ||
:start-after: start-multikey | ||
:end-before: end-multikey | ||
:language: php | ||
:copyable: | ||
:dedent: | ||
|
||
The following is an example of a query that is covered by the index | ||
created in the preceding code example: | ||
|
||
.. io-code-block:: | ||
:copyable: true | ||
|
||
.. input:: /includes/indexes/indexes.php | ||
:start-after: start-index-array-query | ||
:end-before: end-index-array-query | ||
:language: php | ||
:dedent: | ||
|
||
.. output:: | ||
:visible: false | ||
|
||
{"_id":...,"title":"Holi",...,"cast":["Ashutosh Gowariker", | ||
"Aamir Khan","Rahul Ranade","Sanjeev Gandhi"],...} | ||
|
||
Additional Information | ||
---------------------- | ||
|
||
Multikey indexes behave differently from other indexes in terms of query | ||
coverage, index bound computation, and sort behavior. To learn more | ||
about the behavior and limitations of multikey indexes, see | ||
:manual:`Multikey Indexes </core/index-multikey>` in the {+mdb-server+} | ||
manual. | ||
|
||
To view runnable examples that demonstrate how to manage indexes, see | ||
:ref:`php-indexes`. | ||
|
||
API Documentation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
To learn more about any of the methods discussed in this guide, see the following API | ||
documentation: | ||
|
||
- :phpmethod:`MongoDB\Collection::createIndex()` | ||
- :phpmethod:`MongoDB\Collection::findOne()` |
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
Oops, something went wrong.
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.
In the index landing PR (#127), I suggested using some driver functions to print the value as extended JSON. It looks like that was missed in a subsequent PR for single field indexes (#134), upon which I expect this was based.
I'll defer to you if it's worth changing. The expected output in the RST doesn't show any special BSON types, so it's probably of little consequence.
No need for preceding whitespace for a comma. It would be appropriate for a concatenation operator (dot), though.
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 it's ok to use the simpler
json_encode()
method in these contexts. I will change the whitespace though!