From 078ab75145264c568e1b05c46f4589016e81bed3 Mon Sep 17 00:00:00 2001 From: Matija Santl Date: Fri, 19 Oct 2018 10:38:12 +0200 Subject: [PATCH] Fix unique constraint checks Reviewers: mferencevic, teon.banek Reviewed By: teon.banek Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1680 --- .../single_node/indexes/label_property_index.hpp | 13 ++++++++++--- tests/unit/graph_db_accessor_index_api.cpp | 11 +++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/storage/single_node/indexes/label_property_index.hpp b/src/storage/single_node/indexes/label_property_index.hpp index dd0bfb0f9..4c54bbeca 100644 --- a/src/storage/single_node/indexes/label_property_index.hpp +++ b/src/storage/single_node/indexes/label_property_index.hpp @@ -553,10 +553,17 @@ class LabelPropertyIndex { const Vertex *const vertex) { auto access = index.access(); auto it = access.find_or_larger(IndexEntry{value, nullptr, nullptr}); - if (it == access.end() || (IndexEntry::Less(it->value_, value) && - IndexEntry::Less(value, it->value_))) + + // If not found. + if (it == access.end()) { return true; - return false; + } + // If not equal. + if (IndexEntry::Less(it->value_, value) || + IndexEntry::Less(value, it->value_)) { + return true; + } + return vlist->cypher_id() == it->vlist_->cypher_id(); } /** diff --git a/tests/unit/graph_db_accessor_index_api.cpp b/tests/unit/graph_db_accessor_index_api.cpp index e07e43ff4..c78112690 100644 --- a/tests/unit/graph_db_accessor_index_api.cpp +++ b/tests/unit/graph_db_accessor_index_api.cpp @@ -441,3 +441,14 @@ TEST_F(GraphDbAccessorIndex, UniqueConstraintViolationOnBuild) { EXPECT_THROW(dba->BuildIndex(label, property, true), database::IndexConstraintViolationException); } + +TEST_F(GraphDbAccessorIndex, UniqueConstraintUpdateProperty) { + dba->BuildIndex(label, property, true); + AddVertex(0); + auto vertex_accessor = dba->InsertVertex(); + vertex_accessor.add_label(label); + vertex_accessor.PropsSet(property, 10); + + EXPECT_THROW(vertex_accessor.PropsSet(property, 0), + database::IndexConstraintViolationException); +}