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:
parent
d8293f1b6b
commit
078ab75145
@ -553,10 +553,17 @@ class LabelPropertyIndex {
|
|||||||
const Vertex *const vertex) {
|
const Vertex *const vertex) {
|
||||||
auto access = index.access();
|
auto access = index.access();
|
||||||
auto it = access.find_or_larger(IndexEntry{value, nullptr, nullptr});
|
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 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -441,3 +441,14 @@ TEST_F(GraphDbAccessorIndex, UniqueConstraintViolationOnBuild) {
|
|||||||
EXPECT_THROW(dba->BuildIndex(label, property, true),
|
EXPECT_THROW(dba->BuildIndex(label, property, true),
|
||||||
database::IndexConstraintViolationException);
|
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);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user