SERVER-126341: Simplify SBE close() (#53555)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitOrigin-RevId: ee27270a6d96f313280bef8ffc9fa76e83808ba5
This commit is contained in:
Parker Felix 2026-05-19 08:07:33 -04:00 committed by MongoDB Bot
parent 8da2441294
commit 813d9f2c98
39 changed files with 24 additions and 159 deletions

View File

@ -98,7 +98,6 @@ void AggProjectStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_childOpened = true;
}
PlanState AggProjectStage::getNext() {
@ -120,10 +119,7 @@ void AggProjectStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
std::unique_ptr<PlanStageStats> AggProjectStage::getStats(bool includeDebugInfo) const {

View File

@ -90,6 +90,5 @@ private:
vm::ByteCode _bytecode;
bool _compiled{false};
bool _childOpened{false};
};
} // namespace mongo::sbe

View File

@ -152,7 +152,6 @@ void AndHashStage::open(bool reOpen) {
_commonStats.opens++;
_memoryTracker.value().set(0);
_children[0]->open(reOpen);
_outerOpened = true;
// Insert the outer side into the hash table.
while (_children[0]->getNext() == PlanState::ADVANCED) {
value::MaterializedRow key{_inOuterKeyAccessors.size()};
@ -179,10 +178,8 @@ void AndHashStage::open(bool reOpen) {
}
_children[0]->close();
_outerOpened = false;
_children[1]->open(reOpen);
_innerOpened = true;
_htIt = _ht->end();
_htItEnd = _ht->end();
@ -226,14 +223,7 @@ void AndHashStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_innerOpened) {
_children[1]->close();
_innerOpened = false;
}
if (_outerOpened) {
_children[0]->close();
_outerOpened = false;
}
_children[1]->close();
_ht = boost::none;
_memoryTracker.value().set(0);
_specificStats.peakTrackedMemBytes = _memoryTracker.value().peakTrackedMemoryBytes();

View File

@ -136,9 +136,6 @@ private:
// Key used to probe inside the hash table.
value::MaterializedRow _probeKey;
bool _outerOpened{false};
bool _innerOpened{false};
boost::optional<TableType> _ht;
TableType::iterator _htIt;
TableType::iterator _htItEnd;

View File

@ -649,7 +649,6 @@ boost::optional<BlockHashAggStage::TokenizedKeys> BlockHashAggStage::tryTokenize
void BlockHashAggStage::open(bool reOpen) {
auto optTimer(getOptTimer(_opCtx));
_children[0]->open(reOpen);
_childOpened = true;
_commonStats.opens++;
_ht.emplace();
@ -1002,10 +1001,7 @@ void BlockHashAggStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
_ht = boost::none;
if (_recordStore && _opCtx) {

View File

@ -267,7 +267,6 @@ private:
vm::ByteCode _bytecode;
bool _compiled = false;
bool _childOpened{false};
bool _done = false;
// Partial aggregates that have been spilled and restored are passed into the bytecode in

View File

@ -106,7 +106,6 @@ void BlockToRowStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_childOpened = true;
}
PlanState BlockToRowStage::getNextFromDeblockedValues() {
@ -228,10 +227,7 @@ void BlockToRowStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
void BlockToRowStage::doSaveState() {

View File

@ -102,8 +102,6 @@ private:
value::SlotAccessor* _bitmapAccessor = nullptr;
std::vector<value::ViewOfValueAccessor> _valsOutAccessors;
bool _childOpened{false};
// Keeps track of the current reading index of the blocks.
size_t _curIdx = 0;
};

View File

@ -98,7 +98,6 @@ void ExtractFieldPathsStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_childOpened = true;
// Until we have valid data, we disable access to slots.
disableSlotAccess();
@ -192,10 +191,7 @@ void ExtractFieldPathsStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
std::unique_ptr<PlanStageStats> ExtractFieldPathsStage::getStats(bool includeDebugInfo) const {

View File

@ -100,6 +100,5 @@ private:
std::vector<value::OwnedValueAccessor> _outputAccessors;
value::SlotMap<size_t> _outputAccessorsIdxForSlotId;
std::vector<value::ScalarProjectionPositionInfoRecorder> _recorders;
bool _childOpened{false};
};
} // namespace mongo::sbe

View File

@ -193,7 +193,6 @@ void FetchStage::open(bool reOpen) {
_cursor = _coll->getCollectionPtr()->getCursor(_opCtx, true /* forward */);
}
_children[0]->open(reOpen);
_childOpened = true;
_recordIdAccessor.reset(
value::TagValueView{value::TypeTags::RecordId, value::bitcastFrom<RecordId*>(&_seekRid)});
@ -278,10 +277,7 @@ PlanState FetchStage::getNext() {
void FetchStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
_cursor.reset();
}

View File

@ -165,7 +165,6 @@ private:
// Used for index key corruption checks.
StringMap<const IndexCatalogEntry*> _indexCatalogEntryMap;
bool _childOpened{false};
FetchStats _specificStats;
};
} // namespace sbe

View File

@ -517,10 +517,8 @@ void HashAggStage::close() {
_spilledAggRow = {0};
_stashedNextRow = {0, 0};
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
_childOpened = false;
_memoryTracker.value().set(0);
_specificStats.peakTrackedMemBytes = _memoryTracker.value().peakTrackedMemoryBytes();

View File

@ -148,7 +148,6 @@ void HashJoinStage::open(bool reOpen) {
_commonStats.opens++;
innerChild()->open(reOpen);
_innerOpened = true;
_joinImpl->reset();
@ -174,9 +173,7 @@ void HashJoinStage::open(bool reOpen) {
_joinImpl->finishBuild();
innerChild()->close();
_innerOpened = false;
outerChild()->open(reOpen);
_outerOpened = true;
_joinPhase = JoinPhase::kProbing; // Set initial phase
_cursor.reset();
@ -248,14 +245,7 @@ void HashJoinStage::close() {
}
trackClose();
if (_innerOpened) {
innerChild()->close();
_innerOpened = false;
}
if (_outerOpened) {
outerChild()->close();
_outerOpened = false;
}
outerChild()->close();
}
std::unique_ptr<PlanStageStats> HashJoinStage::getStats(bool includeDebugInfo) const {

View File

@ -182,8 +182,6 @@ private:
JoinPhase _joinPhase{JoinPhase::kProbing};
JoinCursor _cursor = JoinCursor::empty();
bool _innerOpened{false};
bool _outerOpened{false};
PlanStage* outerChild() const {
return _children[0].get();

View File

@ -175,7 +175,6 @@ void HashLookupStage::open(bool reOpen) {
// Insert the inner side into the hash table.
innerChild()->open(false);
_innerOpened = true;
value::FixedSizeRow<1 /*N*/> value{1};
while (innerChild()->getNext() == PlanState::ADVANCED) {
// Copy the projected value.
@ -202,9 +201,7 @@ void HashLookupStage::open(bool reOpen) {
}
innerChild()->close();
_innerOpened = false;
outerChild()->open(reOpen);
_outerOpened = true;
} // HashLookupStage::open
template <typename Container>
@ -238,14 +235,7 @@ PlanState HashLookupStage::getNext() {
void HashLookupStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_innerOpened) {
innerChild()->close();
_innerOpened = false;
}
if (_outerOpened) {
outerChild()->close();
_outerOpened = false;
}
outerChild()->close();
reset(true /* fromClose */);
}

View File

@ -188,8 +188,6 @@ private:
// LookupHashTable instance holding the inner collection.
LookupHashTable _hashTable;
bool _innerOpened{false};
bool _outerOpened{false};
void doForceSpill() final {
_hashTable.forceSpill();

View File

@ -164,7 +164,6 @@ void HashLookupUnwindStage::open(bool reOpen) {
// Insert the inner side into the hash table.
innerChild()->open(false);
_innerOpened = true;
while (innerChild()->getNext() == PlanState::ADVANCED) {
value::FixedSizeRow<1 /*N*/> value;
@ -192,9 +191,7 @@ void HashLookupUnwindStage::open(bool reOpen) {
}
innerChild()->close();
_innerOpened = false;
outerChild()->open(reOpen);
_outerOpened = true;
} // HashLookupUnwindStage::open
PlanState HashLookupUnwindStage::getNext() {
@ -241,14 +238,7 @@ PlanState HashLookupUnwindStage::getNext() {
void HashLookupUnwindStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_innerOpened) {
innerChild()->close();
_innerOpened = false;
}
if (_outerOpened) {
outerChild()->close();
_outerOpened = false;
}
outerChild()->close();
reset(true /* fromClose */);
}

View File

@ -172,8 +172,6 @@ private:
// LookupHashTable instance holding the inner collection.
LookupHashTable _hashTable;
bool _innerOpened{false};
bool _outerOpened{false};
// Tracks whether we are already processing an outer key.
bool _outerKeyOpen{false};

View File

@ -85,7 +85,6 @@ void LimitSkipStage::open(bool reOpen) {
_commonStats.opens++;
_commonStats.isEOF = false;
_children[0]->open(reOpen);
_childOpened = true;
_limit = _runLimitOrSkipCode(_limitCode.get());
_skip = _runLimitOrSkipCode(_skipCode.get());
@ -114,10 +113,7 @@ void LimitSkipStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
std::unique_ptr<PlanStageStats> LimitSkipStage::getStats(bool includeDebugInfo) const {

View File

@ -101,7 +101,6 @@ private:
boost::optional<int64_t> _limit;
boost::optional<int64_t> _skip;
int64_t _current;
bool _childOpened{false};
LimitSkipStats _specificStats;
};
} // namespace mongo::sbe

View File

@ -142,7 +142,6 @@ void LoopJoinStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_outerOpened = true;
_outerGetNext = true;
// Do not open the inner child as we do not have values of correlated parameters yet.
// The values are available only after we call getNext on the outer side.
@ -212,10 +211,7 @@ void LoopJoinStage::close() {
++_specificStats.innerCloses;
}
if (_outerOpened) {
_children[0]->close();
_outerOpened = false;
}
_children[0]->close();
}
void LoopJoinStage::doSaveState() {

View File

@ -150,7 +150,6 @@ private:
const JoinType _joinType;
bool _outerOpened{false};
bool _reOpenInner{false};
bool _outerGetNext{false};

View File

@ -167,7 +167,6 @@ void MakeObjStageBase<O>::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_childOpened = true;
}
template <>
@ -515,10 +514,7 @@ void MakeObjStageBase<O>::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
template <typename O>

View File

@ -198,7 +198,6 @@ private:
value::SlotAccessor* _root{nullptr};
bool _compiled{false};
bool _childOpened{false};
};
using MakeObjStage = MakeObjStageBase<MakeObjOutputType::Object>;

View File

@ -188,7 +188,6 @@ void MergeJoinStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_children[1]->open(reOpen);
_childrenOpened = true;
// Start with an initially empty buffer.
_outerProjectsBuffer.clear();
@ -337,11 +336,8 @@ void MergeJoinStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childrenOpened) {
_children[0]->close();
_children[1]->close();
_childrenOpened = false;
}
_children[0]->close();
_children[1]->close();
_outerProjectsBuffer.clear();
_memoryTracker.value().set(0);
_specificStats.peakTrackedMemBytes = _memoryTracker.value().peakTrackedMemoryBytes();

View File

@ -139,8 +139,6 @@ private:
const value::MaterializedRowEq _rowEq;
const value::MaterializedRowLess _rowLt;
bool _childrenOpened{false};
// For when need to EOF earlier after exhausting all of the rows from the outer side.
bool _isOuterDone{false};

View File

@ -83,7 +83,6 @@ void ProjectStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_childOpened = true;
}
PlanState ProjectStage::getNext() {
@ -109,10 +108,7 @@ void ProjectStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
std::unique_ptr<PlanStageStats> ProjectStage::getStats(bool includeDebugInfo) const {

View File

@ -89,7 +89,6 @@ private:
vm::ByteCode _bytecode;
bool _compiled{false};
bool _childOpened{false};
};
template <typename... Ts>

View File

@ -144,7 +144,6 @@ void SortedMergeStage::open(bool reOpen) {
auto& child = _children[i];
child->open(reOpen);
}
_childrenOpened = true;
_merger->init();
}
@ -154,11 +153,8 @@ PlanState SortedMergeStage::getNext() {
void SortedMergeStage::close() {
trackClose();
if (_childrenOpened) {
for (auto& child : _children) {
child->close();
}
_childrenOpened = false;
for (auto& child : _children) {
child->close();
}
_merger->clear();

View File

@ -98,8 +98,6 @@ private:
std::vector<value::SwitchAccessor> _outAccessors;
bool _childrenOpened{false};
// Maintains state about merging the results in order. Initialized during prepare().
boost::optional<SortedStreamMerger<PlanStage>> _merger;
};

View File

@ -111,7 +111,6 @@ void TsBucketToCellBlockStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_childOpened = true;
// Until we have valid data, we disable access to slots.
disableSlotAccess();
@ -152,10 +151,7 @@ void TsBucketToCellBlockStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
std::unique_ptr<PlanStageStats> TsBucketToCellBlockStage::getStats(bool includeDebugInfo) const {

View File

@ -98,8 +98,6 @@ private:
std::vector<std::unique_ptr<value::TsBlock>> _tsBlockStorage;
bool _childOpened{false};
TsBucketToBlockStats _specificStats;
};
} // namespace mongo::sbe

View File

@ -106,7 +106,6 @@ void UniqueStage::open(bool reOpen) {
_memoryTracker->set(0);
}
_children[0]->open(reOpen);
_childOpened = true;
}
PlanState UniqueStage::getNext() {
@ -151,10 +150,7 @@ void UniqueStage::close() {
_prevSeenSizeBytes = 0;
_specificStats.peakTrackedMemBytes = _memoryTracker->peakTrackedMemoryBytes();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
std::unique_ptr<PlanStageStats> UniqueStage::getStats(bool includeDebugInfo) const {
@ -252,7 +248,6 @@ void UniqueRoaringStage::open(bool reOpen) {
_prevSeenSizeBytes = 0;
}
_children[0]->open(reOpen);
_childOpened = true;
}
PlanState UniqueRoaringStage::getNext() {
@ -318,10 +313,7 @@ void UniqueRoaringStage::close() {
_prevSeenSizeBytes = 0;
_specificStats.peakTrackedMemBytes = _memoryTracker->peakTrackedMemoryBytes();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
}
std::unique_ptr<PlanStageStats> UniqueRoaringStage::getStats(bool includeDebugInfo) const {

View File

@ -99,7 +99,6 @@ private:
value::MaterializedRowEq>
_seen;
size_t _prevSeenSizeBytes = 0;
bool _childOpened{false};
UniqueStats _specificStats;
DeduplicatorReporter _dedupReporter;
@ -146,7 +145,6 @@ private:
HashRoaringSet _seen;
size_t _prevSeenSizeBytes = 0;
bool _childOpened{false};
UniqueStats _specificStats;
DeduplicatorReporter _dedupReporter;

View File

@ -104,7 +104,6 @@ void UnwindStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_childOpened = true;
_index = 0;
_inArray = false;
@ -190,10 +189,7 @@ void UnwindStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
_index = 0;
_inArray = false;
}

View File

@ -101,6 +101,5 @@ private:
int64_t _index{0};
bool _inArray{false};
bool _childOpened{false};
};
} // namespace mongo::sbe

View File

@ -554,7 +554,6 @@ void WindowStage::open(bool reOpen) {
_commonStats.opens++;
_children[0]->open(reOpen);
_childOpened = true;
_currId = 0;
freeRows();
@ -734,10 +733,7 @@ void WindowStage::close() {
auto optTimer(getOptTimer(_opCtx));
trackClose();
if (_childOpened) {
_children[0]->close();
_childOpened = false;
}
_children[0]->close();
freeRows();
_memoryTracker.value().set(getMemoryEstimation());

View File

@ -396,7 +396,6 @@ private:
// every document.
long long _failPointSpillCounter{0};
bool _childOpened{false};
WindowStats _specificStats;
};