diff --git a/src/meta/processors/index/CreateEdgeIndexProcessor.cpp b/src/meta/processors/index/CreateEdgeIndexProcessor.cpp index 7fe16120005..85928287333 100644 --- a/src/meta/processors/index/CreateEdgeIndexProcessor.cpp +++ b/src/meta/processors/index/CreateEdgeIndexProcessor.cpp @@ -16,6 +16,7 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) { const auto& indexName = req.get_index_name(); auto& edgeName = req.get_edge_name(); const auto& fields = req.get_fields(); + auto ifNotExists = req.get_if_not_exists(); std::set columnSet; for (const auto& field : fields) { @@ -41,7 +42,7 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) { // check if the space already exist index has the same index name auto ret = getIndexID(space, indexName); if (nebula::ok(ret)) { - if (req.get_if_not_exists()) { + if (ifNotExists) { handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); } else { LOG(INFO) << "Create Edge Index Failed: " << indexName << " has existed"; @@ -96,7 +97,15 @@ void CreateEdgeIndexProcessor::process(const cpp2::CreateEdgeIndexReq& req) { } if (checkIndexExist(fields, item)) { - resp_.code_ref() = nebula::cpp2::ErrorCode::E_EXISTED; + if (ifNotExists) { + resp_.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; + cpp2::ID thriftID; + // Fill index id to avoid broken promise + thriftID.index_id_ref() = item.get_index_id(); + resp_.id_ref() = thriftID; + } else { + resp_.code_ref() = nebula::cpp2::ErrorCode::E_EXISTED; + } onFinished(); return; } diff --git a/src/meta/processors/index/CreateTagIndexProcessor.cpp b/src/meta/processors/index/CreateTagIndexProcessor.cpp index d4c12254902..23ee267c09c 100644 --- a/src/meta/processors/index/CreateTagIndexProcessor.cpp +++ b/src/meta/processors/index/CreateTagIndexProcessor.cpp @@ -16,6 +16,7 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) { const auto& indexName = req.get_index_name(); auto& tagName = req.get_tag_name(); const auto& fields = req.get_fields(); + auto ifNotExists = req.get_if_not_exists(); std::set columnSet; for (const auto& field : fields) { @@ -42,7 +43,7 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) { // check if the space has the index with the same name auto ret = getIndexID(space, indexName); if (nebula::ok(ret)) { - if (req.get_if_not_exists()) { + if (ifNotExists) { handleErrorCode(nebula::cpp2::ErrorCode::SUCCEEDED); } else { LOG(INFO) << "Create Tag Index Failed: " << indexName << " has existed"; @@ -96,7 +97,15 @@ void CreateTagIndexProcessor::process(const cpp2::CreateTagIndexReq& req) { } if (checkIndexExist(fields, item)) { - resp_.code_ref() = nebula::cpp2::ErrorCode::E_EXISTED; + if (ifNotExists) { + resp_.code_ref() = nebula::cpp2::ErrorCode::SUCCEEDED; + cpp2::ID thriftID; + // Fill index id to avoid broken promise + thriftID.index_id_ref() = item.get_index_id(); + resp_.id_ref() = thriftID; + } else { + resp_.code_ref() = nebula::cpp2::ErrorCode::E_EXISTED; + } onFinished(); return; } diff --git a/tests/tck/features/index/Index.feature b/tests/tck/features/index/Index.feature index 8fcc8763177..7d854d3370d 100644 --- a/tests/tck/features/index/Index.feature +++ b/tests/tck/features/index/Index.feature @@ -17,6 +17,11 @@ Feature: IndexTest_Vid_String CREATE TAG INDEX single_tag_index ON tag_1(col2); """ Then the execution should be successful + When executing query: + """ + CREATE TAG INDEX IF NOT EXISTS single_tag_index_1 ON tag_1(col2); + """ + Then the execution should be successful When executing query: """ CREATE TAG INDEX duplicate_tag_index_1 ON tag_1(col2); @@ -155,6 +160,11 @@ Feature: IndexTest_Vid_String CREATE EDGE INDEX single_edge_index ON edge_1(col2); """ Then the execution should be successful + When executing query: + """ + CREATE EDGE INDEX IF NOT EXISTS single_edge_index_1 ON edge_1(col2); + """ + Then the execution should be successful When executing query: """ CREATE EDGE INDEX duplicate_edge_1_index ON edge_1(col2)