diff --git a/deps/oblib/src/common/ob_version_def.h b/deps/oblib/src/common/ob_version_def.h index aad96b98ae..d607dc490a 100644 --- a/deps/oblib/src/common/ob_version_def.h +++ b/deps/oblib/src/common/ob_version_def.h @@ -150,6 +150,7 @@ cal_version(const uint64_t major, const uint64_t minor, const uint64_t major_pat #define MOCK_DATA_VERSION_4_2_1_3 (oceanbase::common::cal_version(4, 2, 1, 3)) #define MOCK_DATA_VERSION_4_2_1_4 (oceanbase::common::cal_version(4, 2, 1, 4)) #define MOCK_DATA_VERSION_4_2_1_5 (oceanbase::common::cal_version(4, 2, 1, 5)) +#define MOCK_DATA_VERSION_4_2_1_8 (oceanbase::common::cal_version(4, 2, 1, 8)) #define DATA_VERSION_4_2_2_0 (oceanbase::common::cal_version(4, 2, 2, 0)) #define MOCK_DATA_VERSION_4_2_2_1 (oceanbase::common::cal_version(4, 2, 2, 1)) #define MOCK_DATA_VERSION_4_2_3_0 (oceanbase::common::cal_version(4, 2, 3, 0)) diff --git a/src/rootserver/ob_root_service.cpp b/src/rootserver/ob_root_service.cpp index cfd6a361ef..11b937121c 100755 --- a/src/rootserver/ob_root_service.cpp +++ b/src/rootserver/ob_root_service.cpp @@ -3351,21 +3351,22 @@ int ObRootService::create_table(const ObCreateTableArg &arg, ObCreateTableRes &r table_exist))) { LOG_WARN("check table exist failed", K(ret), K(table_schema)); } else if (table_exist) { - if (table_schema.is_view_table() && arg.if_not_exist_) { + const ObSimpleTableSchemaV2 *simple_table_schema = nullptr; + if (OB_FAIL(schema_guard.get_simple_table_schema( + table_schema.get_tenant_id(), + table_schema.get_database_id(), + table_schema.get_table_name_str(), + false, /*is index*/ + simple_table_schema))) { + LOG_WARN("failed to get table schema", KR(ret), K(table_schema.get_tenant_id()), + K(table_schema.get_database_id()), K(table_schema.get_table_name_str())); + } else if (OB_ISNULL(simple_table_schema)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("simple_table_schema is null", KR(ret)); + } else if (table_schema.is_view_table() && arg.if_not_exist_) { //create or replace view ... //create user table will drop the old view and recreate it in trans - const ObSimpleTableSchemaV2 *simple_table_schema = nullptr; - if (OB_FAIL(schema_guard.get_simple_table_schema( - table_schema.get_tenant_id(), - table_schema.get_database_id(), - table_schema.get_table_name_str(), - false, /*is index*/ - simple_table_schema))) { - LOG_WARN("failed to get table schema", K(ret)); - } else if (OB_ISNULL(simple_table_schema)) { - ret = OB_ERR_UNEXPECTED; - LOG_WARN("simple_table_schema is null", K(ret)); - } else if ((simple_table_schema->get_table_type() == SYSTEM_VIEW && GCONF.enable_sys_table_ddl) + if ((simple_table_schema->get_table_type() == SYSTEM_VIEW && GCONF.enable_sys_table_ddl) || simple_table_schema->get_table_type() == USER_VIEW || simple_table_schema->get_table_type() == MATERIALIZED_VIEW) { ret = OB_SUCCESS; @@ -3398,6 +3399,15 @@ int ObRootService::create_table(const ObCreateTableArg &arg, ObCreateTableRes &r } } } else { + uint64_t compat_version = 0; + if (OB_FAIL(GET_MIN_DATA_VERSION(table_schema.get_tenant_id(), compat_version))) { + LOG_WARN("fail to get data version", KR(ret), K(table_schema.get_tenant_id())); + } else if ((compat_version >= MOCK_DATA_VERSION_4_2_4_0 && compat_version < DATA_VERSION_4_3_0_0) + ||(compat_version >= MOCK_DATA_VERSION_4_2_1_8 && compat_version < DATA_VERSION_4_2_2_0) + ||(compat_version >= DATA_VERSION_4_3_2_0)) { + res.table_id_ = simple_table_schema->get_table_id(); + res.schema_version_ = simple_table_schema->get_schema_version(); + } ret = OB_ERR_TABLE_EXIST; LOG_WARN("table exist", K(ret), K(table_schema), K(arg.if_not_exist_)); } @@ -3798,6 +3808,7 @@ int ObRootService::create_table(const ObCreateTableArg &arg, ObCreateTableRes &r //create table xx if not exist (...) //create or replace view xx as ... if (arg.if_not_exist_) { + res.do_nothing_ = true; ret = OB_SUCCESS; LOG_INFO("table is exist, no need to create again, ", "tenant_id", table_schema.get_tenant_id(), diff --git a/src/sql/engine/cmd/ob_table_executor.cpp b/src/sql/engine/cmd/ob_table_executor.cpp index 86ec605b43..4454f79096 100644 --- a/src/sql/engine/cmd/ob_table_executor.cpp +++ b/src/sql/engine/cmd/ob_table_executor.cpp @@ -415,7 +415,15 @@ int ObCreateTableExecutor::execute_ctas(ObExecContext &ctx, LOG_WARN("schema_guard reset failed", K(ret)); } else if (OB_FAIL(common_rpc_proxy->create_table(create_table_arg, create_table_res))) { //2, 建表; LOG_WARN("rpc proxy create table failed", K(ret), "dst", common_rpc_proxy->get_server()); - } else if (OB_INVALID_ID != create_table_res.table_id_) { //如果表已存在则后续的查询插入不进行 + } else if (!(OB_INVALID_ID == create_table_res.table_id_ + || (OB_INVALID_ID != create_table_res.table_id_ + && true == create_table_res.do_nothing_)) ) { //如果表已存在则后续的查询插入不进行 + // 1. for old rs + // when table_exist, table_id == invalid_id, and do_nothing will alway be false + // 2. for new rs + // do_nothing is true when table_exist + // --> when table_id == invalid, both old and new rs no table create + // --> when table_id != invalid, both old and new rs do_nothing_ correct if (OB_INVALID_VERSION == create_table_res.schema_version_) { ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected schema version", K(ret), K(create_table_res));