-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 5.0.0-rc0
-
Component/s: Query Execution
-
ALL
-
-
Query Execution 2021-05-31
-
0
In the slot-based execution engine, when running a find or getMore command with a batchSize that exactly matches the number of documents remaining to return, the command response will return a non-zero cursor id:
> db.twodocs.drop() true > db.twodocs.insertMany([{_id: 0}, { _id: 1}]) { "acknowledged" : true, "insertedIds" : [ 0, 1 ] } > db.runCommand({find: "twodocs", batchSize: 1}) { "cursor" : { "firstBatch" : [ { "_id" : 0 } ], "id" : NumberLong("5005687836528864628"), "ns" : "test.twodocs" }, "ok" : 1 } > db.runCommand({getMore: NumberLong("5005687836528864628"), collection: "twodocs", batchSize: 1}) { "cursor" : { "nextBatch" : [ { "_id" : 1 } ], "id" : NumberLong("5005687836528864628"), "ns" : "test.twodocs" }, "ok" : 1 }
Iterating the cursor once more reveals that it is in fact exhausted. This is a regression from the classic engine, as the classic engine would have reported a cursor id of 0 to obviate the need for the final getMore where no results are returned.
> db.runCommand({getMore: NumberLong("5005687836528864628"), collection: "twodocs", batchSize: 1}) { "cursor" : { "nextBatch" : [ ], "id" : NumberLong(0), "ns" : "test.twodocs" }, "ok" : 1 }
The problem also manifests itself with just the find command and an exact batch size matching the result set:
> db.runCommand({find: "twodocs", batchSize: 2}) { "cursor" : { "firstBatch" : [ { "_id" : 0 }, { "_id" : 1 } ], "id" : NumberLong("9219549160796429098"), "ns" : "test.twodocs" }, "ok" : 1 } > db.runCommand({getMore: NumberLong("9219549160796429098"), collection: "twodocs"}) { "cursor" : { "nextBatch" : [ ], "id" : NumberLong(0), "ns" : "test.twodocs" }, "ok" : 1 }
Note that if the final getMore does not include a batch size, the problem doesn't manifest itself:
> db.runCommand({find: "twodocs", batchSize: 1}) { "cursor" : { "firstBatch" : [ { "_id" : 0 } ], "id" : NumberLong("1331269379857468674"), "ns" : "test.twodocs" }, "ok" : 1 } > db.runCommand({getMore: NumberLong("1331269379857468674"), collection: "twodocs"}) { "cursor" : { "nextBatch" : [ { "_id" : 1 } ], "id" : NumberLong(0), "ns" : "test.twodocs" }, "ok" : 1 }
- is depended on by
-
PYTHON-2730 Test failures due unnecessary getMore and killCursors calls in 5.0
- Closed
- is duplicated by
-
SERVER-80713 ID on exhausted cursor no longer 0
- Closed
-
SERVER-83077 Check one getNext beyond batchSize for EOF so we only return a cursor if there are more results
- Closed
- related to
-
SERVER-56094 [SBE][retryable_writes_jscore_stepdown_passthrough] Certain tests fail as they issue unexpected getMore command
- Closed
-
SERVER-56099 [SBE] Fix all PlanStage getNext() methods to use trackPlanState()
- Closed
-
SERVER-96643 When batch size is reached try getting one more document
- Backlog