Skip to content

Commit 14577a5

Browse files
authored
DOCSP-49577-blocking-sort (#11837)
* replace blocking with in-memory * mr feedback * mr feedback * asya feedback * asya feedback * asya feedback
1 parent b10b879 commit 14577a5

11 files changed

+41
-71
lines changed

source/includes/fact-multikey-index-sort-limitation.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
When you sort based on an array field that is indexed with a
2-
:ref:`multikey index <index-type-multikey>`, the query plan includes a
3-
:term:`blocking sort` stage unless both of the following are true:
1+
When you sort based on an array field that is indexed with a :ref:`multikey index
2+
<index-type-multikey>`, the query plan includes an :term:`in-memory sort` stage unless
3+
both of the following are true:
44

55
- The index :ref:`boundaries <multikey-index-bounds-intersecting>` for
66
all sort fields are ``[MinKey, MaxKey]``.

source/reference/command/find.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ The command accepts the following fields:
258258

259259
``allowDiskUse`` has no effect if MongoDB can satisfy the
260260
specified :ref:`sort <find-cmd-sort>` using an index, *or* if the
261-
blocking sort requires less than 100 megabytes of memory.
261+
in-memory sort requires less than 100 megabytes of memory.
262262

263263
For more complete documentation on ``allowDiskUse``,
264264
see :method:`cursor.allowDiskUse()`.
265265

266-
For more information on memory restrictions for large blocking
266+
For more information on memory restrictions for large in-memory
267267
sorts, see :ref:`sort-index-use`.
268268

269269
* - :ref:`let <find-let-syntax>`

source/reference/explain-results.txt

+2-12
Original file line numberDiff line numberDiff line change
@@ -1229,18 +1229,8 @@ Sort Stage
12291229
----------
12301230

12311231
If MongoDB cannot use an index or indexes to obtain the sort order, the
1232-
results include a ``SORT`` stage indicating a blocking sort operation.
1233-
Blocking sorts do not block concurrent operations on the
1234-
collection or database. The name refers to the requirement that the
1235-
``SORT`` stage reads all input documents before returning any output
1236-
documents, blocking the flow of data for that specific query.
1237-
1238-
If MongoDB requires using more than 100 megabytes of system memory for
1239-
the blocking sort operation, MongoDB returns an error *unless* the query
1240-
specifies :method:`cursor.allowDiskUse()`. :method:`cursor.allowDiskUse()`
1241-
allows MongoDB to use temporary files on disk to store data exceeding the 100
1242-
megabyte system memory limit while processing a blocking sort operation. If the
1243-
explain plan does not contain an explicit ``SORT`` stage, then MongoDB can use
1232+
results include a ``SORT`` stage indicating an in-memory sort operation.
1233+
If the explain plan does not contain an explicit ``SORT`` stage, then MongoDB used
12441234
an index to obtain the sort order.
12451235

12461236
.. _explain-output-query-shape-hash:

source/reference/glossary.txt

+11-6
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,8 @@ Glossary
126126

127127
blocking sort
128128
A sort that must be performed in memory before the output is returned.
129-
Blocking sorts may impact performance for large data sets. Use an
130-
:term:`indexed sort` to avoid a blocking sort.
131-
132-
See :ref:`sort-index-use` for more information on blocking sort
133-
operations.
129+
In-memory sorts may impact performance for large data sets. Use an
130+
:term:`indexed sort` to avoid an in-memory sort.
134131

135132
bounded collection scan
136133
A plan used by the :ref:`query optimizer <read-operations-query-optimization>` that
@@ -570,6 +567,14 @@ Glossary
570567
An operation produces the same result with the
571568
same input when run multiple times.
572569

570+
in-memory sort
571+
A sort that must be performed in memory before the output is
572+
returned. In-memory sorts may impact performance for large data sets. Use an
573+
:term:`indexed sort` to avoid an in-memory sort.
574+
575+
See :ref:`sort-index-use` for more information on indexed sort
576+
operations.
577+
573578
index
574579
A data structure that optimizes queries. See :doc:`/indexes`.
575580

@@ -628,7 +633,7 @@ Glossary
628633

629634
indexed sort
630635
A sort where an index provides the sorted result. Sort operations that
631-
use an index often have better performance than a :term:`blocking sort`.
636+
use an index often have better performance than an :term:`in-memory sort`.
632637
See :ref:`Use Indexed to Sort Query Results <sorting-with-indexes>` for
633638
more information.
634639

source/reference/limits.txt

+1-11
Original file line numberDiff line numberDiff line change
@@ -792,17 +792,7 @@ Operations
792792
.. limit:: Sort Operations
793793

794794
If MongoDB cannot use an index or indexes to obtain the sort order,
795-
MongoDB must perform a blocking sort operation on the data. The name
796-
refers to the requirement that the ``SORT`` stage reads all input
797-
documents before returning any output documents, blocking the flow of
798-
data for that specific query.
799-
800-
If MongoDB requires using more than 100 megabytes of system memory
801-
for the blocking sort operation, MongoDB returns an error *unless*
802-
the query specifies :method:`cursor.allowDiskUse()`.
803-
:method:`~cursor.allowDiskUse()` allows MongoDB to use temporary files on
804-
disk to store data exceeding the 100 megabyte system memory limit while
805-
processing a blocking sort operation.
795+
MongoDB must perform an in-memory sort operation on the data.
806796

807797
For more information on sorts and index use, see
808798
:ref:`sort-index-use`.

source/reference/method.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ Cursor
334334

335335
* - :method:`cursor.allowDiskUse()`
336336

337-
- Allows MongoDB to use temporary files on disk to store data exceeding the 100 megabyte system memory limit while processing a blocking sort operation.
337+
- Allows MongoDB to use temporary files on disk to store data exceeding the 100
338+
megabyte system memory limit while processing an in-memory sort operation.
338339

339340
* - :method:`cursor.allowPartialResults()`
340341

source/reference/method/cursor.allowDiskUse.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Definition
3333

3434
db.collection.find(<match>).sort(<sort>).allowDiskUse()
3535

36-
See :ref:`sort-index-use` for more information on blocking sort
36+
See :ref:`sort-index-use` for more information on in-memory sort
3737
operations.
3838

3939
Compatibility
@@ -80,16 +80,16 @@ Supports Large Non-Indexed Sorts Only
8080
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8181

8282
:method:`cursor.allowDiskUse()` has no effect on sort operations
83-
answered using an index *or* non-indexed ("blocking") sort operations
83+
answered using an index *or* non-indexed ("in-memory") sort operations
8484
which require less than 100 megabytes of memory. For more complete
85-
documentation on blocking sorts and sort index use, see
85+
documentation on in-memory sorts and sort index use, see
8686
:ref:`sort-index-use`.
8787

88-
To check if MongoDB must perform an blocking sort, append
88+
To check if MongoDB must perform an in-memory sort, append
8989
:method:`cursor.explain()` to the query and check the
9090
:ref:`explain results <explain-results>`. If the query plan
9191
contains a ``SORT`` stage, then MongoDB must perform an
92-
blocking sort operation subject to the 100 megabyte memory limit.
92+
in-memory sort operation subject to the 100 megabyte memory limit.
9393

9494
Example
9595
-------
@@ -124,7 +124,7 @@ field ``reading.timestamp``. The operation also includes
124124
allowDiskUse()
125125

126126
Since ``reading.timestamp`` is not included in an index, MongoDB
127-
must perform a blocking sort operation to return results in the
127+
must perform an in-memory sort operation to return results in the
128128
requested sort order. By specifying :method:`~cursor.allowDiskUse()`,
129129
MongoDB can process the sort operation *even if* it requires more than
130130
100 megabytes of system memory. If :method:`~cursor.allowDiskUse()`

source/reference/method/cursor.sort.txt

+6-18
Original file line numberDiff line numberDiff line change
@@ -246,29 +246,17 @@ a sort operation *if* the sort uses the same indexes as the query
246246
predicate.
247247

248248
If MongoDB cannot use an index or indexes to obtain the sort
249-
order, MongoDB must perform a blocking sort operation on the data.
250-
A blocking sort indicates that MongoDB must consume and process all
251-
input documents to the sort before returning results. Blocking sorts do
252-
not block concurrent operations on the collection or database.
249+
order, MongoDB must perform an in-memory sort operation on the data.
253250

254251
Sort operations that use an index often have better performance than
255-
blocking sorts. For more information on creating indexes to support
252+
in-memory sorts. For more information on creating indexes to support
256253
sort operations, see :ref:`sorting-with-indexes`.
257254

258-
If MongoDB requires using more than 100 megabytes of system memory for
259-
the blocking sort operation, MongoDB returns an error *unless* the query
260-
specifies :method:`cursor.allowDiskUse()`.
261-
:method:`~cursor.allowDiskUse()` allows MongoDB to use temporary files
262-
on disk to store data exceeding the 100 megabyte system memory limit
263-
while processing a blocking sort operation.
255+
To check if MongoDB must perform an in-memory sort, append :method:`cursor.explain()` to
256+
the query and check the :ref:`explain results <explain-results>`. If the query plan
257+
contains a ``SORT`` stage, then MongoDB must perform an in-memory sort operation.
264258

265-
To check if MongoDB must perform a blocking sort, append
266-
:method:`cursor.explain()` to the query and check the
267-
:ref:`explain results <explain-results>`. If the query plan
268-
contains a ``SORT`` stage, then MongoDB must perform a
269-
blocking sort operation subject to the 100 megabyte memory limit.
270-
271-
To prevent blocking sorts from consuming too much memory:
259+
To prevent in-memory sorts from consuming too much memory:
272260

273261
- Create an index to support the sort operation. See
274262
:doc:`/tutorial/sort-results-with-indexes` for more information and

source/reference/method/js-cursor.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ These methods modify the way that the underlying query is executed.
3535
* - :method:`cursor.allowDiskUse()`
3636
- Allows MongoDB to use temporary files on disk to store data
3737
exceeding the 100 megabyte system memory limit while processing
38-
a blocking sort operation.
38+
an in-memory sort operation.
3939
* - :method:`cursor.allowPartialResults()`
4040
- Allows :method:`db.collection.find()` operations against a
4141
sharded collection to return partial results, rather than an

source/tutorial/equality-sort-range-guideline.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Sort
7171
"Sort" determines the order for results. Sort follows equality matches
7272
because the equality matches reduce the number of documents that need
7373
to be sorted. Sorting after the equality matches also allows MongoDB to
74-
do a non-blocking sort.
74+
do an index sort.
7575

7676
An index can support sort operations when the query fields are a subset
7777
of the index keys. Sort operations on a subset of the index keys are
@@ -115,10 +115,9 @@ Range filters resemble the following:
115115
db.cars.find( { age: { $lt: 10 } } )
116116
db.cars.find( { priorAccidents: { $ne: null } } )
117117

118-
MongoDB cannot perform an index sort on the results of a range filter.
119-
Place the range filter after the sort predicate so MongoDB can use a
120-
non-blocking index sort. For more information on blocking sorts, see
121-
:method:`cursor.allowDiskUse()`.
118+
MongoDB cannot perform an index sort on the results of a range filter. Place the range
119+
filter after the sort predicate so MongoDB can use an index sort. For more information on
120+
in-memory sorts, see :method:`cursor.allowDiskUse()`.
122121

123122
Additional Considerations
124123
-------------------------

source/tutorial/sort-results-with-indexes.txt

+3-6
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ a sort from an index that includes the sort fields. MongoDB *may*
2121
use multiple indexes to support a sort operation *if* the sort uses the
2222
same indexes as the query predicate.
2323

24-
If MongoDB cannot use an index or indexes to obtain the sort
25-
order, MongoDB must perform a blocking sort operation on the data.
26-
A blocking sort indicates that MongoDB must consume and process all
27-
input documents to the sort before returning results. Blocking sorts do
28-
not block concurrent operations on the collection or database.
24+
If MongoDB cannot use an index or indexes to obtain the sort order, MongoDB must perform
25+
an in-memory sort operation on the data.
2926

3027
Starting in MongoDB 6.0, if the server requires more than 100 megabytes
3128
of memory for a pipeline execution stage, MongoDB automatically writes
3229
temporary files to disk unless that query specifies
3330
``{ allowDiskUse: false }``.
3431

3532
Sort operations that use an index often have better performance than
36-
blocking sorts.
33+
in-memory sorts.
3734

3835
.. note::
3936

0 commit comments

Comments
 (0)