We have the following collection of 4 documents and no indices:
If we set batch size and request an unindexed sort, then the server will return just a single batch. This is done so that the server can perform a top k sort.
If we set batch size, and there is index that will provide the sort, then as many batches are returned as required to fully answer the query:
If an index is available which can provide the sort, then the server will always select the plan with the indexed sort. This is key to the old behavior: even if there is a plan with a blocking sort stage that is more efficient, the plan with the indexed sort is preferred.
In the case that
- the batch size is set,
- a sort is requested, and
- there is an index that provides the sort,
the server may or may not select a query plan with a blocking sort. As a consequence, there are some cases in which we expect to get all results from a query back, but instead a plan with a blocking sort is selected and we end up with only one batch.