@@ -1162,6 +1162,15 @@ func (twb *txnWriteBuffer) mergeWithScanResp(
11621162 "with COL_BATCH_RESPONSE scan format" )
11631163 }
11641164
1165+ if twb .buffer .Len () == 0 {
1166+ // If we haven't buffered any writes, then we can just return the server
1167+ // response unchanged.
1168+ // TODO(yuzefovich): we could take the optimization further by examining
1169+ // whether any buffered writes overlap with the Scan request and
1170+ // skipping the merge step if not.
1171+ return resp , nil
1172+ }
1173+
11651174 respIter := newScanRespIter (req , resp )
11661175 // First, calculate the size of the merged response. This then allows us to
11671176 // exactly pre-allocate the response slice when constructing the respMerger.
@@ -1186,6 +1195,15 @@ func (twb *txnWriteBuffer) mergeWithReverseScanResp(
11861195 "ReverseScanRequest with COL_BATCH_RESPONSE scan format" )
11871196 }
11881197
1198+ if twb .buffer .Len () == 0 {
1199+ // If we haven't buffered any writes, then we can just return the server
1200+ // response unchanged.
1201+ // TODO(yuzefovich): we could take the optimization further by examining
1202+ // whether any buffered writes overlap with the ReverseScan request and
1203+ // skipping the merge step if not.
1204+ return resp , nil
1205+ }
1206+
11891207 respIter := newReverseScanRespIter (req , resp )
11901208 // First, calculate the size of the merged response. This then allows us to
11911209 // exactly pre-allocate the response slice when constructing the respMerger.
0 commit comments