From c3067d3640a84117e1b555441c7189cc477fba8e Mon Sep 17 00:00:00 2001 From: gvolfing Date: Tue, 17 Oct 2023 11:37:10 +0200 Subject: [PATCH] Read all the label-proprty indices from disk, independent of further filtering --- src/storage/v2/disk/storage.cpp | 55 +++++++++++---------------------- src/storage/v2/transaction.hpp | 8 ----- src/utils/bound.hpp | 12 +++---- 3 files changed, 24 insertions(+), 51 deletions(-) diff --git a/src/storage/v2/disk/storage.cpp b/src/storage/v2/disk/storage.cpp index 6c102f982..434a25d29 100644 --- a/src/storage/v2/disk/storage.cpp +++ b/src/storage/v2/disk/storage.cpp @@ -199,6 +199,11 @@ bool IsPropertyValueWithinInterval(const PropertyValue &value, return true; } +bool disk_label_property_filter(const std::string &key, const std::string &label_property_prefix, + const std::unordered_set &gids, Gid curr_gid) { + return key.starts_with(label_property_prefix) && !utils::Contains(gids, curr_gid); +} + } // namespace void DiskStorage::LoadTimestampIfExists() { @@ -602,8 +607,7 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p auto merge_with_main_cache = [&](auto &index, auto &index_delta_storage) -> std::unordered_set { index[cache_key] = utils::SkipList(); indexed_vertices = &index[cache_key]; - index_delta_storage.emplace_back(); - index_deltas = &index_delta_storage.back(); + index_deltas = &index_delta_storage.emplace_back(); const auto label_property_filter = [this](const Vertex &vertex, LabelId label, PropertyId property, View view) -> bool { @@ -615,11 +619,6 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p *indexed_vertices, label_property_filter); }; - const auto disk_label_property_filter = [](const std::string &key, const std::string &label_property_prefix, - const std::unordered_set &gids, Gid curr_gid) -> bool { - return key.starts_with(label_property_prefix) && !utils::Contains(gids, curr_gid); - }; - auto &cache = transaction_.label_property_index_cache_; auto &cache_ci = transaction_.label_property_index_cache_ci_; auto &index_delta_storage = transaction_.index_deltas_storage_; @@ -653,7 +652,7 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId property, const PropertyValue &value, View view) { auto *disk_storage = static_cast(storage_); - const auto cache_key = std::make_tuple(label, property, value); + const auto cache_key = std::make_pair(label, property); if (disk_storage->edge_import_status_ == EdgeImportMode::ACTIVE) { HandleLoadingLabelPropertyForEdgeImportCache(label, property); @@ -669,8 +668,7 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p auto merge_with_main_cache = [&](auto &index, auto &index_delta_storage) -> std::unordered_set { index[cache_key] = utils::SkipList(); indexed_vertices = &index[cache_key]; - index_delta_storage.emplace_back(); - index_deltas = &index_delta_storage.back(); + index_deltas = &index_delta_storage.emplace_back(); auto label_property_filter = [this, &value](const Vertex &vertex, LabelId label, PropertyId property, View view) -> bool { @@ -682,8 +680,8 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p *indexed_vertices, label_property_filter); }; - auto &cache = transaction_.label_property_val_index_cache_; - auto &cache_ci = transaction_.label_property_val_index_cache_ci_; + auto &cache = transaction_.label_property_index_cache_; + auto &cache_ci = transaction_.label_property_index_cache_ci_; auto &index_delta_storage = transaction_.index_deltas_storage_; SyncDeletedVertices(cache, cache_key, index_delta_storage, view, merge_with_main_cache); @@ -706,8 +704,8 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p } cache[cache_key] = utils::SkipList(); index_deltas = &index_delta_storage.emplace_back(); - LoadVerticesFromDiskLabelPropertyIndexWithPointValueLookup({}, label, property, value, *index_deltas, - transaction_.vertices_); + LoadVerticesFromDiskLabelPropertyIndex({}, label, property, *index_deltas, transaction_.vertices_, + disk_label_property_filter); merge_with_main_cache(cache, index_delta_storage); return VerticesIterable(AllVerticesIterable(indexed_vertices->access(), storage_, &transaction_, view)); } @@ -717,7 +715,7 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p const std::optional> &upper_bound, View view) { auto *disk_storage = static_cast(storage_); - const auto cache_key = std::make_tuple(label, property, lower_bound, upper_bound); + const auto cache_key = std::make_pair(label, property); if (disk_storage->edge_import_status_ == EdgeImportMode::ACTIVE) { HandleLoadingLabelPropertyForEdgeImportCache(label, property); @@ -731,15 +729,14 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p auto merge_with_main_cache = [&](auto &index, auto &index_delta_storage) -> std::unordered_set { index[cache_key] = utils::SkipList(); indexed_vertices = &index[cache_key]; - index_delta_storage.emplace_back(); - index_deltas = &index_delta_storage.back(); + index_deltas = &index_delta_storage.emplace_back(); return MergeVerticesFromMainCacheWithLabelPropertyIndexCacheForIntervalSearch( label, property, view, lower_bound, upper_bound, *index_deltas, *indexed_vertices); }; - auto &cache = transaction_.label_property_range_index_cache_; - auto &cache_ci = transaction_.label_property_range_index_cache_ci_; + auto &cache = transaction_.label_property_index_cache_; + auto &cache_ci = transaction_.label_property_index_cache_ci_; auto &index_delta_storage = transaction_.index_deltas_storage_; SyncDeletedVertices(cache, cache_key, index_delta_storage, view, merge_with_main_cache); @@ -762,8 +759,8 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, PropertyId p } cache[cache_key] = utils::SkipList(); index_deltas = &index_delta_storage.emplace_back(); - LoadVerticesFromDiskLabelPropertyIndexForIntervalSearch({}, label, property, lower_bound, upper_bound, *index_deltas, - transaction_.vertices_); + LoadVerticesFromDiskLabelPropertyIndex({}, label, property, *index_deltas, transaction_.vertices_, + disk_label_property_filter); merge_with_main_cache(cache, index_delta_storage); return VerticesIterable(AllVerticesIterable(indexed_vertices->access(), storage_, &transaction_, view)); } @@ -1460,14 +1457,6 @@ DiskStorage::DiskAccessor::CheckVertexConstraintsBeforeCommit( return res.GetError(); } - if (auto res = flush_index(transaction_.label_property_val_index_cache_); res.HasError()) { - return res.GetError(); - } - - if (auto res = flush_index(transaction_.label_property_range_index_cache_); res.HasError()) { - return res.GetError(); - } - return {}; } @@ -1609,14 +1598,6 @@ std::optional DiskStorage::FindVertex(storage::Gid gid, Transact return *vertex; } - if (auto vertex = find_in_indices(transaction->label_property_val_index_cache_)) { - return *vertex; - } - - if (auto vertex = find_in_indices(transaction->label_property_range_index_cache_)) { - return *vertex; - } - rocksdb::ReadOptions read_opts; auto strTs = utils::StringTimestamp(transaction->start_timestamp); rocksdb::Slice ts(strTs); diff --git a/src/storage/v2/transaction.hpp b/src/storage/v2/transaction.hpp index 35781ecf5..f74170ca0 100644 --- a/src/storage/v2/transaction.hpp +++ b/src/storage/v2/transaction.hpp @@ -116,18 +116,10 @@ struct Transaction { using LabelIndex = LabelId; using LabelPropertyIndex = std::pair; - using LabelPropertyValIndex = std::tuple; - using RangeBoundary = std::optional>; - using LabelPropertyRangeIndex = std::tuple; - std::map> label_index_cache_; uint64_t label_index_cache_ci_{command_id}; std::map> label_property_index_cache_; uint64_t label_property_index_cache_ci_{command_id}; - std::map> label_property_val_index_cache_; - uint64_t label_property_val_index_cache_ci_{command_id}; - std::map> label_property_range_index_cache_; - uint64_t label_property_range_index_cache_ci_{command_id}; /// We need them because query context for indexed reading is cleared after the query is done not after the /// transaction is done diff --git a/src/utils/bound.hpp b/src/utils/bound.hpp index 4a43e4b50..8fb6b9372 100644 --- a/src/utils/bound.hpp +++ b/src/utils/bound.hpp @@ -33,13 +33,13 @@ class Bound { Bound &operator=(const Bound &other) = default; Bound &operator=(Bound &&other) = default; - bool operator<(const Bound &other) const { - return std::make_tuple(value_, type_) < std::make_tuple(other.value_, other.type_); - } + // bool operator<(const Bound &other) const { + // return std::make_tuple(value_, type_) < std::make_tuple(other.value_, other.type_); + // } - bool operator==(const Bound &other) const { - return std::make_tuple(value_, type_) == std::make_tuple(other.value_, other.type_); - } + // bool operator==(const Bound &other) const { + // return std::make_tuple(value_, type_) == std::make_tuple(other.value_, other.type_); + // } /** Value for the bound. */ const auto &value() const { return value_; }