Fix unique constraint checks

Reviewers: mferencevic, teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1680
This commit is contained in:
Matija Santl 2018-10-19 10:38:12 +02:00
parent d8293f1b6b
commit 078ab75145
2 changed files with 21 additions and 3 deletions

View File

@ -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();
}
/**

View File

@ -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);
}