diff --git a/src/storage/v2/indices.cpp b/src/storage/v2/indices.cpp index 15b81eb8a..34349544f 100644 --- a/src/storage/v2/indices.cpp +++ b/src/storage/v2/indices.cpp @@ -170,7 +170,12 @@ bool CurrentVersionHasLabel(const Vertex &vertex, LabelId label, Transaction *tr deleted = vertex.deleted; has_label = utils::Contains(vertex.labels, label); delta = vertex.delta; + + if (!vertex.label_changed) { + return !deleted && has_label; + } } + ApplyDeltasForRead(transaction, delta, view, [&deleted, &has_label, label](const Delta &delta) { switch (delta.action) { case Delta::Action::REMOVE_LABEL: { @@ -223,7 +228,12 @@ bool CurrentVersionHasLabelProperty(const Vertex &vertex, LabelId label, Propert has_label = utils::Contains(vertex.labels, label); current_value_equal_to_value = vertex.properties.IsPropertyEqual(key, value); delta = vertex.delta; + + if (!vertex.label_changed && !vertex.property_changed) { + return !deleted && has_label && current_value_equal_to_value; + } } + ApplyDeltasForRead(transaction, delta, view, [&deleted, &has_label, ¤t_value_equal_to_value, key, label, &value](const Delta &delta) { switch (delta.action) { diff --git a/src/storage/v2/storage.cpp b/src/storage/v2/storage.cpp index 196bbaec1..c752086e6 100644 --- a/src/storage/v2/storage.cpp +++ b/src/storage/v2/storage.cpp @@ -1015,6 +1015,8 @@ void Storage::Accessor::Abort() { auto vertex = prev.vertex; std::lock_guard guard(vertex->lock); Delta *current = vertex->delta; + vertex->label_changed = false; + vertex->property_changed = false; while (current != nullptr && current->timestamp->load(std::memory_order_acquire) == transaction_.transaction_id.load(std::memory_order_acquire)) { switch (current->action) { @@ -1551,6 +1553,8 @@ void Storage::CollectGarbage() { continue; } vertex->delta = nullptr; + vertex->label_changed = false; + vertex->property_changed = false; if (vertex->deleted) { current_deleted_vertices.push_back(vertex->gid); } diff --git a/src/storage/v2/vertex.hpp b/src/storage/v2/vertex.hpp index 83f517c46..08b3af810 100644 --- a/src/storage/v2/vertex.hpp +++ b/src/storage/v2/vertex.hpp @@ -1,4 +1,4 @@ -// Copyright 2022 Memgraph Ltd. +// Copyright 2023 Memgraph Ltd. // // Use of this software is governed by the Business Source License // included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source @@ -39,8 +39,9 @@ struct Vertex { mutable utils::SpinLock lock; bool deleted; + bool label_changed; + bool property_changed; // uint8_t PAD; - // uint16_t PAD; Delta *delta; }; diff --git a/src/storage/v2/vertex_accessor.cpp b/src/storage/v2/vertex_accessor.cpp index 9682565f9..426e34224 100644 --- a/src/storage/v2/vertex_accessor.cpp +++ b/src/storage/v2/vertex_accessor.cpp @@ -85,6 +85,7 @@ Result VertexAccessor::AddLabel(LabelId label) { if (std::find(vertex_->labels.begin(), vertex_->labels.end(), label) != vertex_->labels.end()) return false; CreateAndLinkDelta(transaction_, vertex_, Delta::RemoveLabelTag(), label); + vertex_->label_changed = true; vertex_->labels.push_back(label);