-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Minor - P4
-
Affects Version/s: None
-
Component/s: Distributed Query Execution
-
None
-
Query Execution
-
Fully Compatible
-
QE 2025-08-18
-
None
-
3
-
TBD
-
None
-
None
-
None
-
None
-
None
-
None
-
None
CursorResponse::parseFromBSON() creates a cursor response from BSON input data.
Cursors normally contain a firstBatch or nextBatch field with a vector of BSONObjs.
When accessing the firstBatch or nextBatch data from the cursor, we currently always copy the batch data here. This is because getFirstBatch() and getNextBatch() return const references to the data, but we cannot assign them to local const reference variable, because the ownership for the contained BSONObjs is later shared, which requires a mutable reference. That's why we currently always copy the vector of BSONObjs.
This is sub-optimal for performance, and we can improve here by adding non-const getters for the AnyCursor::firstBatch and AnyCursor::nextBatch fields. This way we can take a mutable reference to the cursor data in cursor_response.cpp without first copying the entire batch. The cursor is created inside CursorResponse::parseFromBSON() and stored in a local variable inside that function. The batch data is moved out of the function later. So it should be safe to directly operate on the cursor's batch and not on a copy it.