From 86258d2719bff65ba08072237c4a1d38052efb20 Mon Sep 17 00:00:00 2001 From: JLY2015 <1623359870@qq.com> Date: Tue, 24 Sep 2024 12:18:55 +0000 Subject: [PATCH] [vector index] not support vec and fts on same main table --- .../vector_index/ob_vector_index_util.cpp | 29 +++++++++++++++++++ src/share/vector_index/ob_vector_index_util.h | 5 ++++ .../resolver/ddl/ob_create_index_resolver.cpp | 14 ++++++++- .../resolver/ddl/ob_create_table_resolver.cpp | 15 +++++++++- .../resolver/ddl/ob_create_table_resolver.h | 2 ++ 5 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/share/vector_index/ob_vector_index_util.cpp b/src/share/vector_index/ob_vector_index_util.cpp index 93ea0c54f..d6db39a5a 100644 --- a/src/share/vector_index/ob_vector_index_util.cpp +++ b/src/share/vector_index/ob_vector_index_util.cpp @@ -244,6 +244,35 @@ int ObVectorIndexUtil::get_index_name_prefix( return ret; } +int ObVectorIndexUtil::check_table_has_vector_of_fts_index( + const ObTableSchema &data_table_schema, ObSchemaGetterGuard &schema_guard, bool &has_fts_index, bool &has_vec_index) +{ + int ret = OB_SUCCESS; + ObSEArray simple_index_infos; + const int64_t tenant_id = data_table_schema.get_tenant_id(); + has_fts_index = false; + has_vec_index = false; + + if (OB_FAIL(data_table_schema.get_simple_index_infos(simple_index_infos))) { + LOG_WARN("fail to get simple index infos failed", K(ret)); + } else { + for (int64_t i = 0; OB_SUCC(ret) && i < simple_index_infos.count(); ++i) { + const ObTableSchema *index_table_schema = nullptr; + if (OB_FAIL(schema_guard.get_table_schema(tenant_id, simple_index_infos.at(i).table_id_, index_table_schema))) { + LOG_WARN("fail to get index_table_schema", K(ret), K(tenant_id), "table_id", simple_index_infos.at(i).table_id_); + } else if (OB_ISNULL(index_table_schema)) { + ret = OB_TABLE_NOT_EXIST; + LOG_WARN("index table schema should not be null", K(ret), K(simple_index_infos.at(i).table_id_)); + } else if (index_table_schema->is_vec_index()) { + has_vec_index = true; + } else if (index_table_schema->is_fts_index()) { + has_fts_index = true; + } + } + } + return ret; +} + int ObVectorIndexUtil::check_column_has_vector_index( const ObTableSchema &data_table_schema, ObSchemaGetterGuard &schema_guard, const int64_t col_id, bool &is_column_has_vector_index) { diff --git a/src/share/vector_index/ob_vector_index_util.h b/src/share/vector_index/ob_vector_index_util.h index 487312570..4adb83ce2 100644 --- a/src/share/vector_index/ob_vector_index_util.h +++ b/src/share/vector_index/ob_vector_index_util.h @@ -45,6 +45,11 @@ public: static int get_index_name_prefix( const schema::ObTableSchema &index_schema, ObString &prefix); + static int check_table_has_vector_of_fts_index( + const ObTableSchema &data_table_schema, + ObSchemaGetterGuard &schema_guard, + bool &has_fts_index, + bool &has_vec_index); static int check_column_has_vector_index( const ObTableSchema &data_table_schema, ObSchemaGetterGuard &schema_guard, diff --git a/src/sql/resolver/ddl/ob_create_index_resolver.cpp b/src/sql/resolver/ddl/ob_create_index_resolver.cpp index 831ff1350..25266a354 100644 --- a/src/sql/resolver/ddl/ob_create_index_resolver.cpp +++ b/src/sql/resolver/ddl/ob_create_index_resolver.cpp @@ -217,7 +217,19 @@ int ObCreateIndexResolver::resolve_index_column_node( } else { sort_item.prefix_len_ = 0; } - + // not support fts or vec index in same table + if (OB_SUCC(ret)) { + bool has_fts_index = false; + bool has_vec_index = false; + if (OB_FAIL(ObVectorIndexUtil::check_table_has_vector_of_fts_index( + *tbl_schema, *(schema_checker_->get_schema_guard()), has_fts_index, has_vec_index))) { + LOG_WARN("fail to check table has vec of fts index", K(ret)); + } else if ((index_keyname_ == FTS_KEY && has_vec_index) || (index_keyname_ == VEC_KEY && has_fts_index)) { + ret = OB_NOT_SUPPORTED; + LOG_WARN("vector and fts index in same main table is not support", K(ret)); + LOG_USER_ERROR(OB_NOT_SUPPORTED, "vector and fts index in same main table"); + } + } if (OB_FAIL(ret)) { // do nothing } else if (index_keyname_ == FTS_KEY) { diff --git a/src/sql/resolver/ddl/ob_create_table_resolver.cpp b/src/sql/resolver/ddl/ob_create_table_resolver.cpp index 6d03f91dd..c85aff9c7 100644 --- a/src/sql/resolver/ddl/ob_create_table_resolver.cpp +++ b/src/sql/resolver/ddl/ob_create_table_resolver.cpp @@ -63,7 +63,9 @@ ObCreateTableResolver::ObCreateTableResolver(ObResolverParams ¶ms) index_arg_(), current_index_name_set_(), cur_udt_set_id_(0), - vec_index_col_ids_() + vec_index_col_ids_(), + has_vec_index_(false), + has_fts_index_(false) { } @@ -2618,6 +2620,8 @@ int ObCreateTableResolver::resolve_index( SQL_RESV_LOG(WARN, "invalid argument.", K(ret), K(node->children_)); } else { vec_index_col_ids_.reset(); + has_vec_index_ = false; + has_fts_index_ = false; for (int64_t i = 0; OB_SUCC(ret) && i < index_node_position_list.size(); ++i) { reset(); index_attributes_set_ = OB_DEFAULT_INDEX_ATTRIBUTES_SET; @@ -2693,11 +2697,16 @@ int ObCreateTableResolver::resolve_index_node(const ParseNode *node) bool cnt_func_index_mysql = false; bool is_multi_value_index = false; const bool is_vec_index = (index_keyname_ == INDEX_KEYNAME::VEC_KEY); + const bool is_fts_index = (index_keyname_ == INDEX_KEYNAME::FTS_KEY); if (OB_FAIL(ret)) { } else if (is_vec_index && index_column_list_node->num_child_ >= 2) { ret = OB_NOT_SUPPORTED; LOG_WARN("multi column of vector index is not support yet", K(ret), K(index_column_list_node->num_child_)); LOG_USER_ERROR(OB_NOT_SUPPORTED, "multi vector index column is"); + } else if ((is_vec_index && has_fts_index_) || (is_fts_index && has_vec_index_)) { + ret = OB_NOT_SUPPORTED; + LOG_WARN("vector index and fts coexist in main table is not support yet", K(ret), K(index_column_list_node->num_child_)); + LOG_USER_ERROR(OB_NOT_SUPPORTED, "vector index and fts coexist in main table is"); } for (int32_t i = 0; OB_SUCC(ret) && i < index_column_list_node->num_child_; ++i) { ObString &column_name = sort_item.column_name_; @@ -3114,6 +3123,8 @@ int ObCreateTableResolver::resolve_index_node(const ParseNode *node) LOG_WARN("failed to append vec args", K(ret)); } else if (OB_FAIL(vec_index_col_ids_.push_back(vec_index_col_id))) { LOG_WARN("fail to push back vec index col id", K(ret)); + } else { + has_vec_index_ = true; } } else if (is_fts_index(index_arg_.index_type_)) { if (OB_FAIL(ObDDLResolver::append_fts_args(resolve_result, @@ -3123,6 +3134,8 @@ int ObCreateTableResolver::resolve_index_node(const ParseNode *node) index_arg_list, allocator_))) { LOG_WARN("failed to append fts args", K(ret)); + } else { + has_fts_index_ = true; } } else if (is_multivalue_index(index_arg_.index_type_)) { if (OB_FAIL(ObDDLResolver::append_multivalue_args(resolve_result, diff --git a/src/sql/resolver/ddl/ob_create_table_resolver.h b/src/sql/resolver/ddl/ob_create_table_resolver.h index 5539b602b..efcd4f5c1 100644 --- a/src/sql/resolver/ddl/ob_create_table_resolver.h +++ b/src/sql/resolver/ddl/ob_create_table_resolver.h @@ -154,6 +154,8 @@ private: uint64_t cur_udt_set_id_; common::ObSEArray vec_index_col_ids_; + bool has_vec_index_; + bool has_fts_index_; }; } // end namespace sql