//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2014-2016 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 Jan Steemann /// @author Daniel H. Larkin /// @author Simon Grätzer //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGOD_ROCKSDB_ROCKSDB_VPACK_INDEX_H #define ARANGOD_ROCKSDB_ROCKSDB_VPACK_INDEX_H 1 #include #include #include #include #include #include "Aql/AstNode.h" #include "Basics/Common.h" #include "Containers/SmallVector.h" #include "Indexes/IndexIterator.h" #include "RocksDBEngine/RocksDBCuckooIndexEstimator.h" #include "RocksDBEngine/RocksDBFormat.h" #include "RocksDBEngine/RocksDBIndex.h" #include "RocksDBEngine/RocksDBKey.h" #include "RocksDBEngine/RocksDBKeyBounds.h" #include "RocksDBEngine/RocksDBValue.h" #include "VocBase/voc-types.h" #include "VocBase/vocbase.h" namespace arangodb { namespace aql { class SortCondition; struct Variable; } // namespace aql class LogicalCollection; class RocksDBPrimaryIndex; class RocksDBVPackIndex; namespace transaction { class Methods; } class RocksDBVPackIndex : public RocksDBIndex { template friend class RocksDBVPackIndexIterator; public: static uint64_t HashForKey(const rocksdb::Slice& key); RocksDBVPackIndex() = delete; RocksDBVPackIndex(TRI_idx_iid_t iid, LogicalCollection& collection, arangodb::velocypack::Slice const& info); ~RocksDBVPackIndex(); bool hasSelectivityEstimate() const override { return true; } double selectivityEstimate(arangodb::velocypack::StringRef const& = arangodb::velocypack::StringRef()) const override; RocksDBCuckooIndexEstimator* estimator() override; void setEstimator(std::unique_ptr>) override; void recalculateEstimates() override; void toVelocyPack(velocypack::Builder&, std::underlying_type::type) const override; bool canBeDropped() const override { return true; } bool hasCoveringIterator() const override { return true; } /// @brief return the attribute paths std::vector> const& paths() const { return _paths; } /// @brief return the attribute paths, a -1 entry means none is expanding, /// otherwise the non-negative number is the index of the expanding one. std::vector const& expanding() const { return _expanding; } static constexpr size_t minimalPrefixSize() { return sizeof(TRI_voc_tick_t); } /// @brief attempts to locate an entry in the index std::unique_ptr lookup(transaction::Methods*, arangodb::velocypack::Slice const, bool reverse) const; Index::FilterCosts supportsFilterCondition(std::vector> const& allIndexes, arangodb::aql::AstNode const* node, arangodb::aql::Variable const* reference, size_t itemsInIndex) const override; Index::SortCosts supportsSortCondition(arangodb::aql::SortCondition const* sortCondition, arangodb::aql::Variable const* reference, size_t itemsInIndex) const override; arangodb::aql::AstNode* specializeCondition(arangodb::aql::AstNode* node, arangodb::aql::Variable const* reference) const override; std::unique_ptr iteratorForCondition(transaction::Methods* trx, arangodb::aql::AstNode const* node, arangodb::aql::Variable const* reference, IndexIteratorOptions const& opts) override; void afterTruncate(TRI_voc_tick_t tick) override; protected: Result insert(transaction::Methods& trx, RocksDBMethods* methods, LocalDocumentId const& documentId, velocypack::Slice const& doc, Index::OperationMode mode) override; Result remove(transaction::Methods& trx, RocksDBMethods* methods, LocalDocumentId const& documentId, velocypack::Slice const& doc, Index::OperationMode mode) override; Result update(transaction::Methods& trx, RocksDBMethods* methods, LocalDocumentId const& oldDocumentId, velocypack::Slice const& oldDoc, LocalDocumentId const& newDocumentId, velocypack::Slice const& newDoc, Index::OperationMode mode) override; private: /// @brief return the number of paths inline size_t numPaths() const { return _paths.size(); } /// @brief helper function to transform AttributeNames into string lists void fillPaths(std::vector>& paths, std::vector& expanding); /// @brief helper function to insert a document into any index type int fillElement(velocypack::Builder& leased, LocalDocumentId const& documentId, VPackSlice const& doc, ::arangodb::containers::SmallVector& elements, ::arangodb::containers::SmallVector& hashes); /// @brief helper function to build the key and value for rocksdb from the /// vector of slices /// @param hashes list of VPackSlice hashes for the estimator. void addIndexValue(velocypack::Builder& leased, LocalDocumentId const& documentId, VPackSlice const& document, ::arangodb::containers::SmallVector& elements, ::arangodb::containers::SmallVector& hashes, ::arangodb::containers::SmallVector& sliceStack); /// @brief helper function to create a set of value combinations to insert /// into the rocksdb index. /// @param elements vector of resulting index entries /// @param sliceStack working list of values to insert into the index /// @param hashes list of VPackSlice hashes for the estimator. void buildIndexValues(velocypack::Builder& leased, LocalDocumentId const& documentId, VPackSlice const document, size_t level, ::arangodb::containers::SmallVector& elements, ::arangodb::containers::SmallVector& hashes, ::arangodb::containers::SmallVector& sliceStack); private: /// @brief the attribute paths std::vector> _paths; /// @brief ... and which of them expands std::vector _expanding; /// @brief whether or not array indexes will de-duplicate their input values bool _deduplicate; /// @brief whether or not partial indexing is allowed bool _allowPartialIndex; /// @brief A fixed size library to estimate the selectivity of the index. /// On insertion of a document we have to insert it into the estimator, /// On removal we have to remove it in the estimator as well. std::unique_ptr> _estimator; }; } // namespace arangodb #endif