Skip to content

Commit 0e2d140

Browse files
committed
DOCS-960 optimizer logic for ordered and unordered plans
1 parent b1da809 commit 0e2d140

File tree

2 files changed

+50
-27
lines changed

2 files changed

+50
-27
lines changed

source/core/read-operations.txt

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -570,23 +570,39 @@ the collection changes to ensure optimal query plans.
570570

571571
To create a new query plan, the query optimizer:
572572

573-
1. runs the query against several indexes in parallel.
573+
1. runs the query against several candidate indexes in parallel.
574574

575-
#. records the matches in a single common buffer, as though the
576-
results all came from the same index.
575+
#. The query optimizer records the matches in a common results buffer
576+
or buffers:
577+
578+
- If the candidate plans include only :term:`ordered query plans
579+
<ordered query plan>`, there is a single common results buffer.
580+
581+
- If the candidate plans include only :term:`unordered query plans
582+
<unordered query plan>`, there is a single common results buffer.
583+
584+
- If the candidate plans include *both* :term:`ordered query plans
585+
<ordered query plan>` and the :term:`unordered query plans
586+
<unordered query plan>`, there are two common results buffers, one
587+
for the ordered plans and the other for the unordered plans.
577588

578589
If an index returns a result already returned by another index, the
579-
optimizer skips the duplicate match.
590+
optimizer skips the duplicate match. In the case of the two buffers,
591+
both buffers are de-duped.
592+
593+
#. stops the testing of candidate plans and selects an index when one of
594+
the following events occur:
595+
596+
- An :term:`unordered query plan` has returned all the matching results; *or*
597+
598+
- An :term:`ordered query plan` has returned all the matching results; *or*
580599

581-
#. selects an index when either of the following occur:
600+
- An :term:`ordered query plan` has returned a threshold number of matching results:
582601

583-
- The optimizer exhausts an index, which means that the index has
584-
provided the full result set. At this point, the optimizer stops
585-
querying.
602+
- Version 2.0: Threshold is the query batch size. The default
603+
batch size is 101.
586604

587-
- The optimizer reaches 101 results. At this point, the optimizer
588-
chooses the index that has provided the most results *first* and
589-
continues reading only from that index.
605+
- Version 2.2: Threshold is 101.
590606

591607
The selected index becomes the index specified in the query plan;
592608
future iterations of this query or queries with the same query
@@ -618,7 +634,7 @@ use of the different indexes:
618634

619635
This returns the statistics regarding the execution of the query. For
620636
more information on the output of :method:`explain()
621-
<cursor.explain()>` see the :doc:`/reference/explain`.
637+
<cursor.explain()>`, see the :doc:`/reference/explain`.
622638

623639
.. note::
624640

@@ -791,9 +807,9 @@ Consider the following behaviors related to cursors:
791807

792808
- Because the cursor is not isolated during its lifetime, intervening
793809
write operations may result in a cursor that returns a single
794-
document [#single-document-def]_ more than once.
795-
To handle this situation, see the information on :wiki:`snapshot mode
796-
<How to do Snapshotted Queries in the Mongo Database>`.
810+
document [#single-document-def]_ more than once. To handle this
811+
situation, see the information on :ref:`snapshot mode
812+
<faq-developers-isolate-cursors>`.
797813

798814
- The MongoDB server returns the query results in batches:
799815

@@ -906,7 +922,8 @@ operations for more basic data aggregation operations:
906922

907923
- :method:`group()`
908924

909-
- :dbcommand:`mapReduce() <mapReduce>` (See also :wiki:`MapReduce`.)
925+
- :dbcommand:`mapReduce() <mapReduce>` (See also
926+
:doc:`/applications/map-reduce`.)
910927

911928
.. index:: read operation; architecture
912929
.. _read-operations-architecture:

source/reference/glossary.txt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ Glossary
178178
circle
179179
MongoDB's :term:`geospatial` indexes and querying system
180180
allow you to build queries around circles on two-dimensional
181-
coordinate systems. These queries use the
182-
:operator:`$circle` operator to define circle using the center
181+
coordinate systems. These queries use the :operator:`$within` operator
182+
and the :operator:`$center` operator to define a circle using the center
183183
and the radius of the circle.
184184

185185
box
@@ -196,9 +196,7 @@ Glossary
196196
capped collections. Developers may also use capped collections in their
197197
applications.
198198

199-
.. seealso:: The :wiki:`Capped Collections <Capped+Collections>` wiki page.
200-
201-
.. STUB :doc:`/core/capped-collections`.
199+
.. seealso:: The :doc:`/core/capped-collections` page.
202200

203201
BSON types
204202
The set of types supported by the :term:`BSON` serialization
@@ -315,9 +313,7 @@ Glossary
315313

316314
.. include:: /includes/fact-journal-commit-interval-with-gle.rst
317315

318-
.. seealso:: The :wiki:`Journaling` wiki page.
319-
320-
.. STUB :doc:`/core/journaling`.
316+
.. seealso:: The :doc:`/administration/journaling/` page.
321317

322318
pcap
323319
A packet capture format used by :program:`mongosniff` to record
@@ -729,13 +725,11 @@ Glossary
729725
transforms the data. In MongoDB, you can run arbitrary aggregations
730726
over data using map-reduce.
731727

732-
.. seealso:: The :wiki:`Map Reduce <MapReduce>` wiki page for
728+
.. seealso:: The :doc:`/applications/map-reduce` page for
733729
more information regarding MongoDB's map-reduce
734730
implementation, and :doc:`/applications/aggregation` for
735731
another approach to data aggregation in MongoDB.
736732

737-
.. STUB :doc:`/core/map-reduce`
738-
739733
RDBMS
740734
Relational Database Management System. A database management
741735
system based on the relational model, typically using
@@ -911,3 +905,15 @@ Glossary
911905

912906
dot notation
913907
.. include:: /includes/fact-dot-notation.rst
908+
909+
ordered query plan
910+
Query plan that returns results in the order consistent with the
911+
:method:`~cursor.sort()` order.
912+
913+
.. seealso:: :ref:`read-operations-query-optimization`
914+
915+
unordered query plan
916+
Query plan that returns results in an order inconsistent with the
917+
:method:`~cursor.sort()` order.
918+
919+
.. seealso:: :ref:`read-operations-query-optimization`

0 commit comments

Comments
 (0)