|
| 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 |
0 commit comments