From d54acf1b792de6f7a8b82e49a1e94a7c24c938b0 Mon Sep 17 00:00:00 2001 From: Neil Shweky Date: Thu, 4 Nov 2021 18:08:24 +0000 Subject: SERVER-59597 remove unneeded checks in scan --- src/mongo/db/exec/sbe/stages/ix_scan.cpp | 4 --- src/mongo/db/exec/sbe/stages/scan.cpp | 58 ++++++++++++++------------------ 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/mongo/db/exec/sbe/stages/ix_scan.cpp b/src/mongo/db/exec/sbe/stages/ix_scan.cpp index 9e73305f0a1..b913c5575d9 100644 --- a/src/mongo/db/exec/sbe/stages/ix_scan.cpp +++ b/src/mongo/db/exec/sbe/stages/ix_scan.cpp @@ -326,10 +326,6 @@ PlanState IndexScanStage::getNext() { // state in case it yields as the state will be completely overwritten after the call. disableSlotAccess(); - if (!_cursor) { - return trackPlanState(PlanState::IS_EOF); - } - checkForInterrupt(_opCtx); if (_firstGetNext) { diff --git a/src/mongo/db/exec/sbe/stages/scan.cpp b/src/mongo/db/exec/sbe/stages/scan.cpp index 5a50224861a..ea4c7ba85fe 100644 --- a/src/mongo/db/exec/sbe/stages/scan.cpp +++ b/src/mongo/db/exec/sbe/stages/scan.cpp @@ -303,7 +303,7 @@ void ScanStage::open(bool reOpen) { _cursor = _coll->getCursor(_opCtx, _forward); } } else { - _cursor.reset(); + MONGO_UNREACHABLE_TASSERT(5959701); } _open = true; @@ -317,10 +317,6 @@ PlanState ScanStage::getNext() { // case it yields as the state will be completely overwritten after the next() call. disableSlotAccess(); - if (!_cursor) { - return trackPlanState(PlanState::IS_EOF); - } - checkForInterrupt(_opCtx); auto res = _firstGetNext && _seekKeyAccessor; @@ -761,39 +757,37 @@ void ParallelScanStage::open(bool reOpen) { _coll = restoreCollection(_opCtx, *_collName, _collUuid, *_catalogEpoch); } - if (_coll) { - { - stdx::unique_lock lock(_state->mutex); - if (_state->ranges.empty()) { - auto ranges = _coll->getRecordStore()->numRecords(_opCtx) / 10240; - if (ranges < 2) { - _state->ranges.emplace_back(Range{RecordId{}, RecordId{}}); - } else { - if (ranges > 1024) { - ranges = 1024; - } - auto randomCursor = _coll->getRecordStore()->getRandomCursor(_opCtx); - invariant(randomCursor); - std::set rids; - while (ranges--) { - auto nextRecord = randomCursor->next(); - if (nextRecord) { - rids.emplace(nextRecord->id); - } - } - RecordId lastid{}; - for (auto id : rids) { - _state->ranges.emplace_back(Range{lastid, id}); - lastid = id; + { + stdx::unique_lock lock(_state->mutex); + if (_state->ranges.empty()) { + auto ranges = _coll->getRecordStore()->numRecords(_opCtx) / 10240; + if (ranges < 2) { + _state->ranges.emplace_back(Range{RecordId{}, RecordId{}}); + } else { + if (ranges > 1024) { + ranges = 1024; + } + auto randomCursor = _coll->getRecordStore()->getRandomCursor(_opCtx); + invariant(randomCursor); + std::set rids; + while (ranges--) { + auto nextRecord = randomCursor->next(); + if (nextRecord) { + rids.emplace(nextRecord->id); } - _state->ranges.emplace_back(Range{lastid, RecordId{}}); } + RecordId lastid{}; + for (auto id : rids) { + _state->ranges.emplace_back(Range{lastid, id}); + lastid = id; + } + _state->ranges.emplace_back(Range{lastid, RecordId{}}); } } - - _cursor = _coll->getCursor(_opCtx); } + _cursor = _coll->getCursor(_opCtx); + _open = true; } -- cgit v1.2.1