Skip to content

Commit 68017a8

Browse files
pdan101Evergreen Agent
authored andcommitted
SERVER-78162 Set up skeleton for search_cursor_stage class
1 parent cb891c3 commit 68017a8

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed

src/mongo/db/exec/sbe/SConscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ sbeEnv.Library(
8888
'stages/makeobj.cpp',
8989
'stages/merge_join.cpp',
9090
'stages/project.cpp',
91+
'stages/search_cursor.cpp',
9192
'stages/sort.cpp',
9293
'stages/sorted_merge.cpp',
9394
'stages/spool.cpp',
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/**
2+
* Copyright (C) 2023-present MongoDB, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*
17+
* As a special exception, the copyright holders give permission to link the
18+
* code of portions of this program with the OpenSSL library under certain
19+
* conditions as described in each individual source file and distribute
20+
* linked combinations including the program with the OpenSSL library. You
21+
* must comply with the Server Side Public License in all respects for
22+
* all of the code used other than as permitted herein. If you modify file(s)
23+
* with this exception, you may extend this exception to your version of the
24+
* file(s), but you are not obligated to do so. If you do not wish to do so,
25+
* delete this exception statement from your version. If you delete this
26+
* exception statement from all source files in the program, then also delete
27+
* it in the license file.
28+
*/
29+
30+
#include "mongo/db/exec/sbe/stages/search_cursor.h"
31+
#include "mongo/base/string_data.h"
32+
#include "mongo/db/exec/sbe/expressions/compile_ctx.h"
33+
#include "mongo/db/exec/sbe/size_estimator.h"
34+
#include "mongo/db/exec/sbe/values/value.h"
35+
#include "mongo/util/str.h"
36+
37+
namespace mongo::sbe {
38+
SearchCursorStage::SearchCursorStage(boost::optional<value::SlotId> idSlot,
39+
boost::optional<value::SlotId> resultSlot,
40+
std::vector<std::string> metadataNames,
41+
value::SlotVector metadataSlots,
42+
std::vector<std::string> fieldNames,
43+
value::SlotVector fieldSlots,
44+
boost::optional<value::SlotId> searchMetaSlot,
45+
value::SlotId cursorIdSlot,
46+
value::SlotId firstBatchSlot,
47+
PlanYieldPolicy* yieldPolicy,
48+
PlanNodeId planNodeId,
49+
bool participateInTrialRunTracking)
50+
: PlanStage("search_cursor"_sd, yieldPolicy, planNodeId, participateInTrialRunTracking),
51+
_idSlot(std::move(idSlot)),
52+
_resultSlot(std::move(resultSlot)),
53+
_metadataNames(std::move(metadataNames)),
54+
_metadataSlots(std::move(metadataSlots)),
55+
_fieldNames(std::move(fieldNames)),
56+
_fieldSlots(std::move(fieldSlots)),
57+
_searchMetaSlot(std::move(searchMetaSlot)),
58+
_cursorIdSlot(std::move(cursorIdSlot)),
59+
_firstBatchSlot(std::move(firstBatchSlot)) {}
60+
61+
std::unique_ptr<PlanStage> SearchCursorStage::clone() const {
62+
return std::make_unique<SearchCursorStage>(_idSlot,
63+
_resultSlot,
64+
_metadataNames.getUnderlyingVector(),
65+
_metadataSlots,
66+
_fieldNames.getUnderlyingVector(),
67+
_fieldSlots,
68+
_searchMetaSlot,
69+
_cursorIdSlot,
70+
_firstBatchSlot,
71+
_yieldPolicy,
72+
_commonStats.nodeId,
73+
_participateInTrialRunTracking);
74+
}
75+
76+
void SearchCursorStage::prepare(CompileCtx& ctx) {}
77+
78+
value::SlotAccessor* SearchCursorStage::getAccessor(CompileCtx& ctx, value::SlotId slot) {
79+
return ctx.getAccessor(slot);
80+
}
81+
void SearchCursorStage::open(bool reOpen) {
82+
auto optTimer(getOptTimer(_opCtx));
83+
84+
_commonStats.opens++;
85+
}
86+
87+
PlanState SearchCursorStage::getNext() {
88+
auto optTimer(getOptTimer(_opCtx));
89+
90+
return trackPlanState(PlanState::ADVANCED);
91+
}
92+
93+
void SearchCursorStage::close() {
94+
auto optTimer(getOptTimer(_opCtx));
95+
96+
trackClose();
97+
}
98+
99+
std::unique_ptr<PlanStageStats> SearchCursorStage::getStats(bool includeDebugInfo) const {
100+
auto ret = std::make_unique<PlanStageStats>(_commonStats);
101+
return ret;
102+
}
103+
104+
const SpecificStats* SearchCursorStage::getSpecificStats() const {
105+
return nullptr;
106+
}
107+
108+
std::vector<DebugPrinter::Block> SearchCursorStage::debugPrint() const {
109+
auto ret = PlanStage::debugPrint();
110+
return ret;
111+
}
112+
113+
size_t SearchCursorStage::estimateCompileTimeSize() const {
114+
size_t size = sizeof(*this);
115+
size += size_estimator::estimate(_children);
116+
size += size_estimator::estimate(_metadataSlots);
117+
size += size_estimator::estimate(_fieldSlots);
118+
return size;
119+
}
120+
121+
} // namespace mongo::sbe
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright (C) 2023-present MongoDB, Inc.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the Server Side Public License, version 1,
6+
* as published by MongoDB, Inc.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* Server Side Public License for more details.
12+
*
13+
* You should have received a copy of the Server Side Public License
14+
* along with this program. If not, see
15+
* <http://www.mongodb.com/licensing/server-side-public-license>.
16+
*
17+
* As a special exception, the copyright holders give permission to link the
18+
* code of portions of this program with the OpenSSL library under certain
19+
* conditions as described in each individual source file and distribute
20+
* linked combinations including the program with the OpenSSL library. You
21+
* must comply with the Server Side Public License in all respects for
22+
* all of the code used other than as permitted herein. If you modify file(s)
23+
* with this exception, you may extend this exception to your version of the
24+
* file(s), but you are not obligated to do so. If you do not wish to do so,
25+
* delete this exception statement from your version. If you delete this
26+
* exception statement from all source files in the program, then also delete
27+
* it in the license file.
28+
*/
29+
30+
#pragma once
31+
32+
#include <cstddef>
33+
#include <memory>
34+
#include <utility>
35+
#include <vector>
36+
37+
#include "mongo/db/exec/plan_stats.h"
38+
#include "mongo/db/exec/sbe/expressions/expression.h"
39+
#include "mongo/db/exec/sbe/stages/plan_stats.h"
40+
#include "mongo/db/exec/sbe/stages/stages.h"
41+
#include "mongo/db/exec/sbe/util/debug_print.h"
42+
#include "mongo/db/exec/sbe/values/slot.h"
43+
#include "mongo/db/query/stage_types.h"
44+
45+
namespace mongo::sbe {
46+
/**
47+
* TODO: Description of search_cursor_stage.
48+
*
49+
*
50+
* Debug string representation:
51+
*
52+
* search_cursor_stage optionalIdSlot optionalResultSlot [metaSlot1, …, metadataSlotN] [fieldSlot1,
53+
* …, fieldSlotN] optionalSearchMetaSlot
54+
*/
55+
class SearchCursorStage final : public PlanStage {
56+
public:
57+
SearchCursorStage(boost::optional<value::SlotId> idSlot,
58+
boost::optional<value::SlotId> resultSlot,
59+
std::vector<std::string> metadataNames,
60+
value::SlotVector metadataSlots,
61+
std::vector<std::string> fieldNames,
62+
value::SlotVector fieldSlots,
63+
boost::optional<value::SlotId> searchMetaSlot,
64+
value::SlotId cursorIdSlot,
65+
value::SlotId firstBatchSlot,
66+
PlanYieldPolicy* yieldPolicy,
67+
PlanNodeId planNodeId,
68+
bool participateInTrialRunTracking = true);
69+
70+
std::unique_ptr<PlanStage> clone() const final;
71+
72+
void prepare(CompileCtx& ctx) final;
73+
value::SlotAccessor* getAccessor(CompileCtx& ctx, value::SlotId slot) final;
74+
void open(bool reOpen) final;
75+
PlanState getNext() final;
76+
void close() final;
77+
78+
std::unique_ptr<PlanStageStats> getStats(bool includeDebugInfo) const final;
79+
const SpecificStats* getSpecificStats() const final;
80+
std::vector<DebugPrinter::Block> debugPrint() const final override;
81+
size_t estimateCompileTimeSize() const final;
82+
83+
private:
84+
const boost::optional<value::SlotId> _idSlot;
85+
const boost::optional<value::SlotId> _resultSlot;
86+
const IndexedStringVector _metadataNames;
87+
const value::SlotVector _metadataSlots;
88+
const IndexedStringVector _fieldNames;
89+
const value::SlotVector _fieldSlots;
90+
const boost::optional<value::SlotId> _searchMetaSlot;
91+
const value::SlotId _cursorIdSlot;
92+
const value::SlotId _firstBatchSlot;
93+
};
94+
95+
template <typename... Ts>
96+
inline auto makeSearchCursorStage(std::unique_ptr<PlanStage> input,
97+
PlanNodeId nodeId,
98+
Ts&&... pack) {
99+
return makeS<SearchCursorStage>(std::move(input), makeEM(std::forward<Ts>(pack)...), nodeId);
100+
}
101+
} // namespace mongo::sbe

0 commit comments

Comments
 (0)