From 4a3f950cf94d5eb3e411b2757bc891f9464fb19a Mon Sep 17 00:00:00 2001 From: jbajic Date: Thu, 1 Dec 2022 15:00:23 +0100 Subject: [PATCH] Fix indices --- src/storage/v3/indices.cpp | 23 +++++++++++------------ src/storage/v3/indices.hpp | 4 ++-- src/storage/v3/property_value.hpp | 4 ++-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/storage/v3/indices.cpp b/src/storage/v3/indices.cpp index 503972b42..0dbb13481 100644 --- a/src/storage/v3/indices.cpp +++ b/src/storage/v3/indices.cpp @@ -21,7 +21,6 @@ #include "storage/v3/mvcc.hpp" #include "storage/v3/property_value.hpp" #include "storage/v3/schemas.hpp" -#include "storage/v3/vertices_container.hpp" #include "utils/bound.hpp" #include "utils/logging.hpp" #include "utils/memory_tracker.hpp" @@ -392,13 +391,13 @@ bool LabelPropertyIndex::Entry::operator<(const PropertyValue &rhs) const { retu bool LabelPropertyIndex::Entry::operator==(const PropertyValue &rhs) const { return value == rhs; } void LabelPropertyIndex::UpdateOnAddLabel(LabelId label, Vertex *vertex, const Transaction &tx) { - for (auto &[label_prop, container] : index_) { + for (auto &[label_prop, index] : index_) { if (label_prop.first != label) { continue; } auto prop_value = vertex->properties.GetProperty(label_prop.second); if (!prop_value.IsNull()) { - container.emplace(vertex->keys, Entry{std::move(prop_value), vertex, tx.start_timestamp.logical_id}); + index.emplace(prop_value, Entry{prop_value, vertex, tx.start_timestamp.logical_id}); } } } @@ -408,12 +407,12 @@ void LabelPropertyIndex::UpdateOnSetProperty(PropertyId property, const Property if (value.IsNull()) { return; } - for (auto &[label_prop, container] : index_) { + for (auto &[label_prop, index] : index_) { if (label_prop.second != property) { continue; } if (utils::Contains(vertex->labels, label_prop.first)) { - container.emplace(vertex->keys, Entry{value, vertex, tx.start_timestamp.logical_id}); + index.emplace(value, Entry{value, vertex, tx.start_timestamp.logical_id}); } } } @@ -435,7 +434,7 @@ bool LabelPropertyIndex::CreateIndex(LabelId label, PropertyId property, VertexC if (value.IsNull()) { continue; } - it->second.emplace(vertex.keys, Entry{std::move(value), &vertex, 0}); + it->second.emplace(value, Entry{value, &vertex, 0}); } } catch (const utils::OutOfMemoryException &) { utils::MemoryTracker::OutOfMemoryExceptionBlocker oom_exception_blocker; @@ -455,8 +454,8 @@ std::vector> LabelPropertyIndex::ListIndices() co } void LabelPropertyIndex::RemoveObsoleteEntries(const uint64_t clean_up_before_timestamp) { - for (auto &[label_property, container] : index_) { - for (auto it = container.begin(); it != container.end();) { + for (auto &[label_property, index] : index_) { + for (auto it = index.begin(); it != index.end();) { auto next_it = it; ++next_it; @@ -465,11 +464,11 @@ void LabelPropertyIndex::RemoveObsoleteEntries(const uint64_t clean_up_before_ti continue; } - if (auto &entry = it->second; - (next_it != container.end() && entry.vertex == next_it->second.vertex && entry.value == entry.value) || + if (auto &entry = it->second, &next_entry = next_it->second; + (next_it != index.end() && entry.vertex == next_entry.vertex && entry.value == next_entry.value) || !AnyVersionHasLabelProperty(*entry.vertex, label_property.first, label_property.second, entry.value, clean_up_before_timestamp)) { - container.erase(it->first); + index.erase(it->first); } it = next_it; } @@ -683,7 +682,7 @@ int64_t LabelPropertyIndex::VertexCount(LabelId label, PropertyId property, if (value->IsInclusive()) { return found_it; } - return ++found_it; + return found_it != it->second.end() ? ++found_it : found_it; } return def; }; diff --git a/src/storage/v3/indices.hpp b/src/storage/v3/indices.hpp index 7f159acb2..d1e5ba737 100644 --- a/src/storage/v3/indices.hpp +++ b/src/storage/v3/indices.hpp @@ -17,10 +17,10 @@ #include #include "storage/v3/config.hpp" +#include "storage/v3/containers.hpp" #include "storage/v3/property_value.hpp" #include "storage/v3/transaction.hpp" #include "storage/v3/vertex_accessor.hpp" -#include "storage/v3/vertices_container.hpp" #include "utils/bound.hpp" #include "utils/logging.hpp" #include "utils/skip_list.hpp" @@ -133,7 +133,6 @@ class LabelIndex { }; class LabelPropertyIndex { - public: struct Entry { PropertyValue value; Vertex *vertex; @@ -146,6 +145,7 @@ class LabelPropertyIndex { bool operator==(const PropertyValue &rhs) const; }; + public: using LabelPropertyIndexContainer = std::map; LabelPropertyIndex(Indices *indices, Config::Items config, const VertexValidator &vertex_validator) diff --git a/src/storage/v3/property_value.hpp b/src/storage/v3/property_value.hpp index 4b81d90b4..e1e4b4d67 100644 --- a/src/storage/v3/property_value.hpp +++ b/src/storage/v3/property_value.hpp @@ -331,7 +331,7 @@ inline bool operator<(const PropertyValue &first, const PropertyValue &second) { } inline bool operator>=(const PropertyValue &first, const PropertyValue &second) { - if (!PropertyValue::AreComparableTypes(first.type(), second.type())) return first.type() < second.type(); + if (!PropertyValue::AreComparableTypes(first.type(), second.type())) return first.type() >= second.type(); switch (first.type()) { case PropertyValue::Type::Null: return false; @@ -347,7 +347,7 @@ inline bool operator>=(const PropertyValue &first, const PropertyValue &second) if (second.type() == PropertyValue::Type::Double) { return first.ValueDouble() >= second.ValueDouble(); } else { - return first.ValueDouble() < static_cast(second.ValueInt()); + return first.ValueDouble() >= static_cast(second.ValueInt()); } case PropertyValue::Type::String: return first.ValueString() >= second.ValueString();