diff --git a/CHANGELOG.md b/CHANGELOG.md index 787de2c76..eebd48264 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * `indexInfo()` function replaced with `SHOW INDEX INFO` syntax. * Write-ahead log format changed (not backward compatible). * Snapshot format changed (not backward compatible). +* Removed support for unique index. Use unique constraints instead. ### Major Features and Improvements diff --git a/src/query/frontend/ast/ast.lcp b/src/query/frontend/ast/ast.lcp index 889faf778..621025ae9 100644 --- a/src/query/frontend/ast/ast.lcp +++ b/src/query/frontend/ast/ast.lcp @@ -1540,7 +1540,7 @@ cpp<# :clone (clone-name-ix-vector "Property"))) (:public (lcp:define-enum action - (create create-unique drop) + (create drop) (:serialize)) #>cpp diff --git a/src/query/frontend/ast/cypher_main_visitor.cpp b/src/query/frontend/ast/cypher_main_visitor.cpp index c8a4a251a..de409be24 100644 --- a/src/query/frontend/ast/cypher_main_visitor.cpp +++ b/src/query/frontend/ast/cypher_main_visitor.cpp @@ -159,19 +159,6 @@ antlrcpp::Any CypherMainVisitor::visitCreateIndex( return index_query; } -antlrcpp::Any CypherMainVisitor::visitCreateUniqueIndex( - MemgraphCypher::CreateUniqueIndexContext *ctx) { - auto *index_query = storage_->Create<IndexQuery>(); - index_query->action_ = IndexQuery::Action::CREATE_UNIQUE; - index_query->label_ = AddLabel(ctx->labelName()->accept(this)); - index_query->properties_.reserve(ctx->propertyKeyName().size()); - for (const auto &prop_name : ctx->propertyKeyName()) { - PropertyIx name_key = prop_name->accept(this); - index_query->properties_.push_back(name_key); - } - return index_query; -} - antlrcpp::Any CypherMainVisitor::visitDropIndex( MemgraphCypher::DropIndexContext *ctx) { auto *index_query = storage_->Create<IndexQuery>(); diff --git a/src/query/frontend/ast/cypher_main_visitor.hpp b/src/query/frontend/ast/cypher_main_visitor.hpp index 294f99737..3194f5b02 100644 --- a/src/query/frontend/ast/cypher_main_visitor.hpp +++ b/src/query/frontend/ast/cypher_main_visitor.hpp @@ -243,12 +243,6 @@ class CypherMainVisitor : public antlropencypher::MemgraphCypherBaseVisitor { antlrcpp::Any visitCreateIndex( MemgraphCypher::CreateIndexContext *ctx) override; - /** - * @return CreateUniqueIndex* - */ - antlrcpp::Any visitCreateUniqueIndex( - MemgraphCypher::CreateUniqueIndexContext *ctx) override; - /** * @return DropIndex* */ diff --git a/src/query/frontend/opencypher/grammar/Cypher.g4 b/src/query/frontend/opencypher/grammar/Cypher.g4 index d060f55fc..36f089628 100644 --- a/src/query/frontend/opencypher/grammar/Cypher.g4 +++ b/src/query/frontend/opencypher/grammar/Cypher.g4 @@ -56,7 +56,7 @@ profileQuery : PROFILE cypherQuery ; cypherQuery : singleQuery ( cypherUnion )* ; -indexQuery : createIndex | createUniqueIndex | dropIndex; +indexQuery : createIndex | dropIndex; singleQuery : clause ( clause )* ; @@ -299,8 +299,6 @@ integerLiteral : DecimalLiteral createIndex : CREATE INDEX ON ':' labelName '(' propertyKeyName ')' ; -createUniqueIndex : CREATE UNIQUE INDEX ON ':' labelName '(' propertyKeyName ( ',' propertyKeyName )* ')' ; - dropIndex : DROP INDEX ON ':' labelName '(' propertyKeyName ')' ; doubleLiteral : FloatingLiteral ; diff --git a/src/query/interpreter.cpp b/src/query/interpreter.cpp index e7b970b15..17b21a1f1 100644 --- a/src/query/interpreter.cpp +++ b/src/query/interpreter.cpp @@ -533,7 +533,6 @@ Callback HandleStreamQuery(StreamQuery *stream_query, Callback HandleIndexQuery(IndexQuery *index_query, std::function<void()> invalidate_plan_cache, database::GraphDbAccessor *db_accessor) { - auto action = index_query->action_; auto label = db_accessor->Label(index_query->label_.name); std::vector<storage::Property> properties; properties.reserve(index_query->properties_.size()); @@ -547,15 +546,8 @@ Callback HandleIndexQuery(IndexQuery *index_query, Callback callback; switch (index_query->action_) { - case IndexQuery::Action::CREATE_UNIQUE: -#ifdef MG_SINGLE_NODE - throw QueryRuntimeException( - "Unique index is not supported, use unique constraint instead "); -#else - throw QueryRuntimeException("Unique index is not supported"); -#endif case IndexQuery::Action::CREATE: - callback.fn = [action, label, properties, db_accessor, + callback.fn = [label, properties, db_accessor, invalidate_plan_cache] { try { CHECK(properties.size() == 1); diff --git a/tests/unit/ast_serialization.cpp b/tests/unit/ast_serialization.cpp index 5a8a0b578..e68510744 100644 --- a/tests/unit/ast_serialization.cpp +++ b/tests/unit/ast_serialization.cpp @@ -1662,35 +1662,6 @@ TEST_P(CypherMainVisitorTest, CreateIndex) { EXPECT_EQ(index_query->properties_, expected_properties); } -TEST_P(CypherMainVisitorTest, CreateUniqueIndex) { - auto &ast_generator = *GetParam(); - auto *index_query = dynamic_cast<IndexQuery *>( - ast_generator.ParseQuery("Create unIqUe InDeX oN :mirko(slavko, pero)")); - ASSERT_TRUE(index_query); - EXPECT_EQ(index_query->action_, IndexQuery::Action::CREATE_UNIQUE); - EXPECT_EQ(index_query->label_, ast_generator.Label("mirko")); - std::vector<PropertyIx> expected_properties{ast_generator.Prop("slavko"), - ast_generator.Prop("pero")}; - ASSERT_EQ(index_query->properties_, expected_properties); -} - -TEST_P(CypherMainVisitorTest, CreateUniqueIndexWithoutProperties) { - auto &ast_generator = *GetParam(); - EXPECT_THROW(ast_generator.ParseQuery("Create unIqUe InDeX oN :mirko()"), - SyntaxException); -} - -TEST_P(CypherMainVisitorTest, CreateUniqueIndexWithSingleProperty) { - auto &ast_generator = *GetParam(); - auto *index_query = dynamic_cast<IndexQuery *>( - ast_generator.ParseQuery("Create unIqUe InDeX oN :mirko(slavko)")); - ASSERT_TRUE(index_query); - EXPECT_EQ(index_query->action_, IndexQuery::Action::CREATE_UNIQUE); - EXPECT_EQ(index_query->label_, ast_generator.Label("mirko")); - std::vector<PropertyIx> expected_properties{ast_generator.Prop("slavko")}; - ASSERT_EQ(index_query->properties_, expected_properties); -} - TEST_P(CypherMainVisitorTest, DropIndex) { auto &ast_generator = *GetParam(); auto *index_query = dynamic_cast<IndexQuery *>( diff --git a/tests/unit/cypher_main_visitor.cpp b/tests/unit/cypher_main_visitor.cpp index 6cc628219..c08a40c06 100644 --- a/tests/unit/cypher_main_visitor.cpp +++ b/tests/unit/cypher_main_visitor.cpp @@ -1766,35 +1766,6 @@ TEST_P(CypherMainVisitorTest, CreateIndex) { EXPECT_EQ(index_query->properties_, expected_properties); } -TEST_P(CypherMainVisitorTest, CreateUniqueIndex) { - auto &ast_generator = *GetParam(); - auto *index_query = dynamic_cast<IndexQuery *>( - ast_generator.ParseQuery("Create unIqUe InDeX oN :mirko(slavko, pero)")); - ASSERT_TRUE(index_query); - EXPECT_EQ(index_query->action_, IndexQuery::Action::CREATE_UNIQUE); - EXPECT_EQ(index_query->label_, ast_generator.Label("mirko")); - std::vector<PropertyIx> expected_properties{ast_generator.Prop("slavko"), - ast_generator.Prop("pero")}; - ASSERT_EQ(index_query->properties_, expected_properties); -} - -TEST_P(CypherMainVisitorTest, CreateUniqueIndexWithoutProperties) { - auto &ast_generator = *GetParam(); - EXPECT_THROW(ast_generator.ParseQuery("Create unIqUe InDeX oN :mirko()"), - SyntaxException); -} - -TEST_P(CypherMainVisitorTest, CreateUniqueIndexWithSingleProperty) { - auto &ast_generator = *GetParam(); - auto *index_query = dynamic_cast<IndexQuery *>( - ast_generator.ParseQuery("Create unIqUe InDeX oN :mirko(slavko)")); - ASSERT_TRUE(index_query); - EXPECT_EQ(index_query->action_, IndexQuery::Action::CREATE_UNIQUE); - EXPECT_EQ(index_query->label_, ast_generator.Label("mirko")); - std::vector<PropertyIx> expected_properties{ast_generator.Prop("slavko")}; - ASSERT_EQ(index_query->properties_, expected_properties); -} - TEST_P(CypherMainVisitorTest, DropIndex) { auto &ast_generator = *GetParam(); auto *index_query = dynamic_cast<IndexQuery *>(