//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2014-2019 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Heiko Kernbach //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGOD_AQL_DOCUMENT_PRODUCING_HELPER_H #define ARANGOD_AQL_DOCUMENT_PRODUCING_HELPER_H 1 #include "Aql/types.h" #include "VocBase/voc-types.h" #include #include #include #include namespace arangodb { class LocalDocumentId; namespace transaction { class Methods; } namespace velocypack { class Builder; class Slice; } namespace aql { class Expression; class InputAqlItemRow; class OutputAqlItemRow; class Query; enum class ProjectionType : uint32_t { IdAttribute, KeyAttribute, OtherAttribute }; using DocumentProducingFunction = std::function; void handleProjections(std::vector> const& projections, transaction::Methods const* trxPtr, velocypack::Slice slice, velocypack::Builder& b, bool useRawDocumentPointers); struct DocumentProducingFunctionContext { public: DocumentProducingFunctionContext(InputAqlItemRow const& inputRow, OutputAqlItemRow* outputRow, RegisterId outputRegister, bool produceResult, Query* query, Expression* filter, std::vector const& projections, std::vector const& coveringIndexAttributePositions, bool allowCoveringIndexOptimization, bool useRawDocumentPointers, bool checkUniqueness); DocumentProducingFunctionContext() = delete; ~DocumentProducingFunctionContext() = default; void setOutputRow(OutputAqlItemRow* outputRow); bool getProduceResult() const noexcept; std::vector> const& getProjections() const noexcept; transaction::Methods* getTrxPtr() const noexcept; std::vector const& getCoveringIndexAttributePositions() const noexcept; bool getAllowCoveringIndexOptimization() const noexcept; bool getUseRawDocumentPointers() const noexcept; void setAllowCoveringIndexOptimization(bool allowCoveringIndexOptimization) noexcept; void incrScanned() noexcept; void incrFiltered() noexcept; size_t getAndResetNumScanned() noexcept; size_t getAndResetNumFiltered() noexcept; InputAqlItemRow const& getInputRow() const noexcept; OutputAqlItemRow& getOutputRow() const noexcept; RegisterId getOutputRegister() const noexcept; bool checkUniqueness(LocalDocumentId const& token); bool checkFilter(velocypack::Slice slice); void reset(); void setIsLastIndex(bool val); bool hasFilter() const noexcept; private: InputAqlItemRow const& _inputRow; OutputAqlItemRow* _outputRow; Query* const _query; Expression* _filter; std::vector> _projections; std::vector const& _coveringIndexAttributePositions; size_t _numScanned; size_t _numFiltered; /// @brief set of already returned documents. Used to make the result distinct std::unordered_set _alreadyReturned; RegisterId const _outputRegister; bool const _produceResult; bool const _useRawDocumentPointers; bool _allowCoveringIndexOptimization; /// @brief Flag if the current index pointer is the last of the list. /// Used in uniqueness checks. bool _isLastIndex; /// @brief Flag if we need to check for uniqueness bool _checkUniqueness; }; namespace DocumentProducingCallbackVariant { struct WithProjectionsCoveredByIndex {}; struct WithProjectionsNotCoveredByIndex {}; struct DocumentWithRawPointer {}; struct DocumentCopy {}; } // namespace DocumentProducingCallbackVariant template DocumentProducingFunction getCallback(DocumentProducingCallbackVariant::WithProjectionsCoveredByIndex, DocumentProducingFunctionContext& context); template DocumentProducingFunction getCallback(DocumentProducingCallbackVariant::WithProjectionsNotCoveredByIndex, DocumentProducingFunctionContext& context); template DocumentProducingFunction getCallback(DocumentProducingCallbackVariant::DocumentWithRawPointer, DocumentProducingFunctionContext& context); template DocumentProducingFunction getCallback(DocumentProducingCallbackVariant::DocumentCopy, DocumentProducingFunctionContext& context); template std::function getNullCallback(DocumentProducingFunctionContext& context); template DocumentProducingFunction buildCallback(DocumentProducingFunctionContext& context); } // namespace aql } // namespace arangodb #endif