diff --git a/src/observer/virtual_table/ob_show_create_table.cpp b/src/observer/virtual_table/ob_show_create_table.cpp index 72e13d153..3cf1541b6 100644 --- a/src/observer/virtual_table/ob_show_create_table.cpp +++ b/src/observer/virtual_table/ob_show_create_table.cpp @@ -116,6 +116,8 @@ int ObShowCreateTable::fill_row_cells(uint64_t show_table_id, uint64_t cell_idx = 0; char *table_def_buf = NULL; int64_t table_def_buf_size = OB_MAX_VARCHAR_LENGTH; + bool strict_mode = false; + bool is_oracle_mode = false; if (OB_UNLIKELY(NULL == schema_guard_ || NULL == session_ || NULL == allocator_ @@ -138,7 +140,14 @@ int ObShowCreateTable::fill_row_cells(uint64_t show_table_id, } else if (OB_UNLIKELY(NULL == (table_def_buf = static_cast(allocator_->alloc(table_def_buf_size))))) { ret = OB_ALLOCATE_MEMORY_FAILED; SERVER_LOG(ERROR, "fail to alloc table_def_buf", K(ret)); + } else if (OB_FAIL(table_schema.check_if_oracle_compat_mode(is_oracle_mode))) { + SERVER_LOG(WARN, "failed to check if oracle mode", K(ret)); + } else if (OB_FAIL(session_->get_show_ddl_in_compat_mode(strict_mode))) { + SERVER_LOG(WARN, "failed to get _show_ddl_in_compat_mode", K(ret)); } else { + //_show_ddl_in_compat_mode do not support oracle mode now + strict_mode &= !is_oracle_mode; + for (int64_t i = 0; OB_SUCC(ret) && i < output_column_ids_.count(); ++i) { uint64_t col_id = output_column_ids_.at(i); switch(col_id) { @@ -156,7 +165,7 @@ int ObShowCreateTable::fill_row_cells(uint64_t show_table_id, } case OB_APP_MIN_COLUMN_ID + 2: { // create_table - ObSchemaPrinter schema_printer(*schema_guard_); + ObSchemaPrinter schema_printer(*schema_guard_, strict_mode); int64_t pos = 0; if (table_schema.is_view_table()) { if (OB_FAIL(schema_printer.print_view_definiton(effective_tenant_id_, diff --git a/src/share/schema/ob_schema_printer.cpp b/src/share/schema/ob_schema_printer.cpp index 3ca7db5fe..9d626fda9 100644 --- a/src/share/schema/ob_schema_printer.cpp +++ b/src/share/schema/ob_schema_printer.cpp @@ -48,8 +48,8 @@ using namespace common; /*----------------------------------------------------------------------------- * ObSchemaPrinter *-----------------------------------------------------------------------------*/ -ObSchemaPrinter::ObSchemaPrinter(ObSchemaGetterGuard &schema_guard) - : schema_guard_(schema_guard) +ObSchemaPrinter::ObSchemaPrinter(ObSchemaGetterGuard &schema_guard, bool strict_compat) + : schema_guard_(schema_guard), strict_compat_(strict_compat) { } @@ -606,12 +606,12 @@ int ObSchemaPrinter::print_single_index_definition(const ObTableSchema *index_sc if (OB_SUCC(ret)) { if (OB_FAIL(print_index_column(table_schema, last_col, ctxcat_cols, true /* last column */, buf, buf_len, pos))) { SHARE_SCHEMA_LOG(WARN, "fail to print column name", K(ret), K(last_col)); - } else if (OB_FAIL(print_table_definition_fulltext_indexs(is_oracle_mode, ctxcat_cols, buf, buf_len, pos))) { + } else if (!strict_compat_ && OB_FAIL(print_table_definition_fulltext_indexs(is_oracle_mode, ctxcat_cols, buf, buf_len, pos))) { LOG_WARN("print table definition fulltext indexs failed", K(ret)); } else { /*do nothing*/ } } // show storing columns in index - if (OB_SUCC(ret) && !is_no_key_options(sql_mode)) { + if (OB_SUCC(ret) && !strict_compat_ && !is_no_key_options(sql_mode)) { int64_t column_count = index_schema->get_column_count(); if (column_count >= rowkey_count) { bool first_storing_column = true; @@ -703,6 +703,10 @@ int ObSchemaPrinter::print_table_definition_indexes(const ObTableSchema &table_s && INDEX_TYPE_UNIQUE_LOCAL != index_schema->get_index_type()) { // In oracle mode, only the non-partitioned unique index can be printed as an unique constraint, other unique indexes will not be printed. continue; + } else if (strict_compat_ && (index_schema->is_global_index_table() || + index_schema->is_global_local_index_table())) { + // For strictly compatible with MySQL, + // Do not print global index. } else if (OB_FAIL(print_single_index_definition(index_schema, table_schema, arena_allocator, buf, buf_len, pos, is_unique_index, is_oracle_mode, false, sql_mode, tz_info))) { LOG_WARN("print single index definition failed", K(ret)); @@ -1395,7 +1399,7 @@ int ObSchemaPrinter::print_table_definition_store_format(const ObTableSchema &ta } else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s ", store_format_name))) { SHARE_SCHEMA_LOG(WARN, "fail to print store format", K(ret), K(table_schema), K(store_format)); } - if (OB_SUCC(ret) && !is_oracle_mode) { + if (OB_SUCC(ret) && !strict_compat_ && !is_oracle_mode) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "COMPRESSION = '%s' ", table_schema.is_compressed() ? table_schema.get_compress_func_name() : "none"))) { SHARE_SCHEMA_LOG(WARN, "fail to print compress method", K(ret), K(table_schema)); @@ -1536,7 +1540,7 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t } if (OB_FAIL(databuff_printf(buf, buf_len, pos, "AUTO_INCREMENT = %lu ", auto_increment))) { SHARE_SCHEMA_LOG(WARN, "fail to print auto increment", K(ret), K(auto_increment), K(table_schema)); - } else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "AUTO_INCREMENT_MODE = '%s' ", + } else if (!strict_compat_ && OB_FAIL(databuff_printf(buf, buf_len, pos, "AUTO_INCREMENT_MODE = '%s' ", table_schema.is_order_auto_increment_mode() ? "ORDER" : "NOORDER"))) { SHARE_SCHEMA_LOG(WARN, "fail to print auto increment mode", K(ret), K(table_schema)); } @@ -1571,7 +1575,7 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t SHARE_SCHEMA_LOG(WARN, "fail to print store format", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl && !is_no_table_options(sql_mode) + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && !is_no_table_options(sql_mode) && table_schema.get_expire_info().length() > 0 && NULL != table_schema.get_expire_info().ptr()) { const ObString expire_str = table_schema.get_expire_info(); @@ -1580,7 +1584,7 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t SHARE_SCHEMA_LOG(WARN, "fail to print expire info", K(ret), K(expire_str)); } } - if (OB_SUCCESS == ret && !is_index_tbl && !is_no_table_options(sql_mode)) { + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && !is_no_table_options(sql_mode)) { int64_t paxos_replica_num = OB_INVALID_COUNT; if (OB_FAIL(table_schema.get_paxos_replica_num(schema_guard_, paxos_replica_num))) { LOG_WARN("fail to get paxos replica num", K(ret)); @@ -1594,7 +1598,7 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t SHARE_SCHEMA_LOG(INFO, "XXX", K(paxos_replica_num)); } // no more to do } - if (OB_SUCCESS == ret && table_schema.get_block_size() >= 0 + if (OB_SUCCESS == ret && !strict_compat_ && table_schema.get_block_size() >= 0 && !is_no_key_options(sql_mode) && !is_no_table_options(sql_mode)) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, is_index_tbl ? "BLOCK_SIZE %ld " : "BLOCK_SIZE = %ld ", @@ -1602,7 +1606,7 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t SHARE_SCHEMA_LOG(WARN, "fail to print block size", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && is_index_tbl && !table_schema.is_domain_index() + if (OB_SUCCESS == ret && !strict_compat_ && is_index_tbl && !table_schema.is_domain_index() && !is_no_key_options(sql_mode)) { const char* local_flag = table_schema.is_global_index_table() || table_schema.is_global_local_index_table() @@ -1611,7 +1615,7 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t SHARE_SCHEMA_LOG(WARN, "fail to print global/local", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl && !is_no_table_options(sql_mode)) { + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && !is_no_table_options(sql_mode)) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "USE_BLOOM_FILTER = %s ", table_schema.is_use_bloomfilter() ? "TRUE" : "FALSE"))) { SHARE_SCHEMA_LOG(WARN, "fail to print use bloom filter", K(ret), K(table_schema)); @@ -1624,26 +1628,27 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t SHARE_SCHEMA_LOG(WARN, "fail to print row movement option", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl && !is_no_table_options(sql_mode)) { + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && !is_no_table_options(sql_mode)) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "TABLET_SIZE = %ld ", table_schema.get_tablet_size()))) { SHARE_SCHEMA_LOG(WARN, "fail to print tablet_size", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl && !is_no_table_options(sql_mode)) { + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && !is_no_table_options(sql_mode)) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "PCTFREE = %ld ", table_schema.get_pctfree()))) { SHARE_SCHEMA_LOG(WARN, "fail to print pctfree", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl && table_schema.get_dop() > 1 + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && table_schema.get_dop() > 1 && !is_no_table_options(sql_mode)) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "PARALLEL %ld ", table_schema.get_dop()))) { SHARE_SCHEMA_LOG(WARN, "fail to print dop", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl && common::OB_INVALID_ID != table_schema.get_tablegroup_id() + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl + && common::OB_INVALID_ID != table_schema.get_tablegroup_id() && !is_no_table_options(sql_mode)) { const ObTablegroupSchema *tablegroup_schema = schema_guard_.get_tablegroup_schema( tenant_id, table_schema.get_tablegroup_id()); @@ -1664,7 +1669,8 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t } } - if (OB_SUCCESS == ret && !is_index_tbl && table_schema.get_progressive_merge_num() > 0 + if (OB_SUCCESS == ret && !strict_compat_ + && !is_index_tbl && table_schema.get_progressive_merge_num() > 0 && !is_no_table_options(sql_mode)) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "PROGRESSIVE_MERGE_NUM = %ld ", table_schema.get_progressive_merge_num()))) { @@ -1688,14 +1694,14 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t SHARE_SCHEMA_LOG(WARN, "fail to print tablespace option", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl && table_schema.is_read_only() + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && table_schema.is_read_only() && !is_no_table_options(sql_mode)) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "READ ONLY "))) { SHARE_SCHEMA_LOG(WARN, "fail to print table read only", K(ret)); } } ObString table_mode_str = ""; - if (OB_SUCC(ret) && !is_index_tbl && !is_no_table_options(sql_mode)) { + if (OB_SUCC(ret) && !strict_compat_ && !is_index_tbl && !is_no_table_options(sql_mode)) { if (!agent_mode) { if (table_schema.is_queuing_table()) { table_mode_str = "QUEUING"; @@ -1704,12 +1710,12 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t table_mode_str = ObBackUpTableModeOp::get_table_mode_str(table_schema.get_table_mode_struct()); } } - if (OB_SUCC(ret) && table_mode_str.length() > 0 && !is_no_table_options(sql_mode)) { + if (OB_SUCC(ret) && !strict_compat_ && table_mode_str.length() > 0 && !is_no_table_options(sql_mode)) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "TABLE_MODE = '%s' ", table_mode_str.ptr()))) { SHARE_SCHEMA_LOG(WARN, "fail to print table table_mode", K(ret)); } } - if (OB_SUCC(ret) && agent_mode) { + if (OB_SUCC(ret) && !strict_compat_ && agent_mode) { if (OB_FAIL(!is_index_tbl ? databuff_printf(buf, buf_len, pos, "TABLE_ID = %lu ", table_schema.get_table_id()) : databuff_printf(buf, buf_len, pos, "INDEX_TABLE_ID = %lu DATA_TABLE_ID = %lu", @@ -1718,6 +1724,7 @@ int ObSchemaPrinter::print_table_definition_table_options(const ObTableSchema &t } } if (OB_SUCC(ret) + && !strict_compat_ && ObDuplicateScopeChecker::is_valid_replicate_scope(table_schema.get_duplicate_scope()) && !is_no_table_options(sql_mode)) { // 目前只支持cluster @@ -1883,6 +1890,9 @@ int ObSchemaPrinter::print_table_definition_partition_options(const ObTableSchem const ObPartitionSchema *partition_schema = &table_schema; if (PARTITION_LEVEL_TWO == table_schema.get_part_level()) { is_subpart = true; + if (strict_compat_) { + is_subpart &= is_subpartition_valid_in_mysql(table_schema); + } } if (OB_FAIL(databuff_printf(buf, buf_len, pos, "\n"))) { SHARE_SCHEMA_LOG(WARN, "fail to print enter", K(ret)); @@ -1896,23 +1906,28 @@ int ObSchemaPrinter::print_table_definition_partition_options(const ObTableSchem SHARE_SCHEMA_LOG(WARN, "fail to printf partition expr", K(ret), K(disp_part_fun_expr_str)); } else if (OB_FAIL(print_interval_if_ness(table_schema, buf, buf_len, pos, tz_info))) { SHARE_SCHEMA_LOG(WARN, "fail to print interval", K(ret)); - } else if (is_subpart && partition_schema->sub_part_template_def_valid()) { + } else if (!strict_compat_ && is_subpart && partition_schema->sub_part_template_def_valid()) { if (OB_FAIL(print_template_sub_partition_elements(partition_schema, buf, buf_len, pos, tz_info, false))) { SHARE_SCHEMA_LOG(WARN, "fail to print sub partition elements", K(ret)); } } if (OB_SUCC(ret)) { + bool print_sub_part_element = is_subpart && + (strict_compat_ || !partition_schema->sub_part_template_def_valid()); if (table_schema.is_range_part()) { - if (OB_FAIL(print_range_partition_elements(partition_schema, buf, buf_len, pos, agent_mode, false, tz_info))) { + if (OB_FAIL(print_range_partition_elements(partition_schema, buf, buf_len, pos, + print_sub_part_element, agent_mode, false, tz_info))) { SHARE_SCHEMA_LOG(WARN, "fail to print partition elements", K(ret)); } } else if (table_schema.is_list_part()) { - if (OB_FAIL(print_list_partition_elements(partition_schema, buf, buf_len, pos, agent_mode, false, tz_info))) { + if (OB_FAIL(print_list_partition_elements(partition_schema, buf, buf_len, pos, + print_sub_part_element, agent_mode, false, tz_info))) { SHARE_SCHEMA_LOG(WARN, "fail to print partition elements", K(ret)); } } else if (is_hash_like_part(table_schema.get_part_option().get_part_func_type())) { - if (OB_FAIL(print_hash_partition_elements(partition_schema, buf, buf_len, pos, agent_mode, tz_info))) { + if (OB_FAIL(print_hash_partition_elements(partition_schema, buf, buf_len, pos, + print_sub_part_element, agent_mode, tz_info))) { SHARE_SCHEMA_LOG(WARN, "fail to print partition elements", K(ret)); } } @@ -1983,7 +1998,7 @@ int ObSchemaPrinter::print_table_definition_table_options( LOG_WARN("fail to check oracle mode", KR(ret), K(table_schema)); } - if (OB_SUCCESS == ret && !is_index_tbl && !is_for_table_status && is_agent_mode) { + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && !is_for_table_status && is_agent_mode) { uint64_t auto_increment = 0; if (OB_ISNULL(sql_proxy)) { ret = OB_ERR_UNEXPECTED; @@ -2025,7 +2040,7 @@ int ObSchemaPrinter::print_table_definition_table_options( if (full_text_columns.count() <= 0 || OB_UNLIKELY(virtual_column_id == OB_INVALID_ID)) { ret = OB_ERR_UNEXPECTED; OB_LOG(WARN, "invalid domain index infos", K(full_text_columns), K(virtual_column_id)); - } else if (OB_FAIL(print_table_definition_fulltext_indexs( + } else if (!strict_compat_ && OB_FAIL(print_table_definition_fulltext_indexs( is_oracle_mode, full_text_columns, virtual_column_id, buf, buf_len, pos))) { OB_LOG(WARN, "failed to print table definition full text indexes", K(ret)); } else if (table_schema.get_parser_name_str().empty()) { @@ -2047,7 +2062,7 @@ int ObSchemaPrinter::print_table_definition_table_options( OB_LOG(WARN, "fail to print expire info", K(ret), K(expire_str)); } } - if (OB_SUCC(ret) && !is_index_tbl) { + if (OB_SUCC(ret) && !strict_compat_ && !is_index_tbl) { int64_t paxos_replica_num = OB_INVALID_COUNT; if (OB_FAIL(table_schema.get_paxos_replica_num(schema_guard_, paxos_replica_num))) { OB_LOG(WARN, "fail to get paxos replica num", K(ret)); @@ -2060,14 +2075,15 @@ int ObSchemaPrinter::print_table_definition_table_options( OB_LOG(WARN, "fail to print replica num", K(ret), K(table_schema)); } } - if (OB_SUCC(ret) && table_schema.get_block_size() >= 0 && !is_index_tbl) { + if (OB_SUCC(ret) && !strict_compat_ + && table_schema.get_block_size() >= 0 && !is_index_tbl) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "BLOCK_SIZE = %ld ", table_schema.get_block_size()))) { OB_LOG(WARN, "fail to print block size", K(ret), K(table_schema)); } } - if (OB_SUCC(ret) && is_index_tbl && !table_schema.is_domain_index()) { + if (OB_SUCC(ret) && !strict_compat_ && is_index_tbl && !table_schema.is_domain_index()) { const char* local_flag = table_schema.is_global_index_table() || table_schema.is_global_local_index_table() ? "GLOBAL " : "LOCAL "; @@ -2075,31 +2091,32 @@ int ObSchemaPrinter::print_table_definition_table_options( OB_LOG(WARN, "fail to print global/local", K(ret), K(table_schema)); } } - if (OB_SUCC(ret) && !is_index_tbl) { + if (OB_SUCC(ret) && !strict_compat_ && !is_index_tbl) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "USE_BLOOM_FILTER = %s ", table_schema.is_use_bloomfilter() ? "TRUE" : "FALSE"))) { OB_LOG(WARN, "fail to print use bloom filter", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl) { + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "TABLET_SIZE = %ld ", table_schema.get_tablet_size()))) { SHARE_SCHEMA_LOG(WARN, "fail to print tablet_size", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl) { + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "PCTFREE = %ld ", table_schema.get_pctfree()))) { SHARE_SCHEMA_LOG(WARN, "fail to print pctfree", K(ret), K(table_schema)); } } - if (OB_SUCCESS == ret && !is_index_tbl && table_schema.get_dop() > 1) { + if (OB_SUCCESS == ret && !strict_compat_ && !is_index_tbl && table_schema.get_dop() > 1) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "PARALLEL %ld ", table_schema.get_dop()))) { SHARE_SCHEMA_LOG(WARN, "fail to print dop", K(ret), K(table_schema)); } } - if (OB_SUCC(ret) && !is_index_tbl && common::OB_INVALID_ID != table_schema.get_tablegroup_id()) { + if (OB_SUCC(ret) && !strict_compat_ + && !is_index_tbl && common::OB_INVALID_ID != table_schema.get_tablegroup_id()) { const ObTablegroupSchema *tablegroup_schema = schema_guard_.get_tablegroup_schema( tenant_id, table_schema.get_tablegroup_id()); if (NULL != tablegroup_schema) { @@ -2119,14 +2136,15 @@ int ObSchemaPrinter::print_table_definition_table_options( } } - if (OB_SUCC(ret) && !is_index_tbl && table_schema.get_progressive_merge_num() > 0) { + if (OB_SUCC(ret) && !strict_compat_ + && !is_index_tbl && table_schema.get_progressive_merge_num() > 0) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "PROGRESSIVE_MERGE_NUM = %ld ", table_schema.get_progressive_merge_num()))) { OB_LOG(WARN, "fail to print progressive merge num", K(ret), K(table_schema)); } } - if (OB_SUCC(ret) && is_agent_mode) { + if (OB_SUCC(ret) && !strict_compat_ && is_agent_mode) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "PROGRESSIVE_MERGE_ROUND = %ld ", table_schema.get_progressive_merge_round()))) { OB_LOG(WARN, "fail to print progressive merge round", K(ret), K(table_schema)); @@ -2140,27 +2158,27 @@ int ObSchemaPrinter::print_table_definition_table_options( OB_LOG(WARN, "fail to print comment", K(ret), K(table_schema)); } } - if (OB_SUCC(ret) && !is_index_tbl && table_schema.is_read_only()) { + if (OB_SUCC(ret) && !strict_compat_ && !is_index_tbl && table_schema.is_read_only()) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "READ ONLY "))) { SHARE_SCHEMA_LOG(WARN, "fail to print table read only", K(ret)); } } // backup table mode ObString table_mode_str = ""; - if (OB_SUCC(ret) && !is_index_tbl) { - if (!is_agent_mode) { - if (table_schema.is_queuing_table()) { - table_mode_str = "QUEUING"; - } - } else { // true == agent_mode - table_mode_str = ObBackUpTableModeOp::get_table_mode_str(table_schema.get_table_mode_struct()); + if (OB_SUCC(ret) && !strict_compat_ && !is_index_tbl) { + if (!is_agent_mode) { + if (table_schema.is_queuing_table()) { + table_mode_str = "QUEUING"; } + } else { // true == agent_mode + table_mode_str = ObBackUpTableModeOp::get_table_mode_str(table_schema.get_table_mode_struct()); } - if (OB_SUCC(ret) && table_mode_str.length() > 0) { - if (OB_FAIL(databuff_printf(buf, buf_len, pos, "TABLE_MODE = '%s' ", table_mode_str.ptr()))) { - SHARE_SCHEMA_LOG(WARN, "fail to print table table_mode", K(ret)); - } + } + if (OB_SUCC(ret) && !strict_compat_ && table_mode_str.length() > 0) { + if (OB_FAIL(databuff_printf(buf, buf_len, pos, "TABLE_MODE = '%s' ", table_mode_str.ptr()))) { + SHARE_SCHEMA_LOG(WARN, "fail to print table table_mode", K(ret)); } + } //table_id for backup and restore if (OB_SUCC(ret) && !is_index_tbl && is_agent_mode) { @@ -2524,7 +2542,7 @@ int ObSchemaPrinter::print_index_table_definition( } else if (OB_FAIL(print_table_definition_table_options( *index_table_schema, full_text_columns, virtual_column_id, buf, buf_len, pos, false, NULL, is_agent_mode))) { OB_LOG(WARN, "fail to print table options", K(ret), K(*index_table_schema)); - } else if (OB_FAIL(print_table_index_stroing(index_table_schema, table_schema, buf, buf_len, pos))) { + } else if (!strict_compat_ && OB_FAIL(print_table_index_stroing(index_table_schema, table_schema, buf, buf_len, pos))) { OB_LOG(WARN, "fail to print partition table index storing", K(ret), K(*index_table_schema), K(*table_schema)); } else if (index_table_schema->is_global_index_table() && OB_FAIL(print_table_definition_partition_options(*index_table_schema, buf, buf_len, pos, is_agent_mode, tz_info))) { @@ -2719,12 +2737,15 @@ int ObSchemaPrinter::print_tablegroup_definition_partition_options( if (OB_SUCC(ret)) { bool tablegroup_def = true; + bool print_sub_part_element = !partition_schema->sub_part_template_def_valid(); if (tablegroup_schema.is_range_part()) { - if (OB_FAIL(print_range_partition_elements(partition_schema, buf, buf_len, pos, agent_mode, tablegroup_def, tz_info))) { + if (OB_FAIL(print_range_partition_elements(partition_schema, buf, buf_len, pos, + print_sub_part_element, agent_mode, tablegroup_def, tz_info))) { SHARE_SCHEMA_LOG(WARN, "fail to print partition elements", K(ret)); } } else if (tablegroup_schema.is_list_part()) { - if (OB_FAIL(print_list_partition_elements(partition_schema, buf, buf_len, pos, agent_mode, tablegroup_def, tz_info))) { + if (OB_FAIL(print_list_partition_elements(partition_schema, buf, buf_len, pos, + print_sub_part_element, agent_mode, tablegroup_def, tz_info))) { SHARE_SCHEMA_LOG(WARN, "fail to print partition elements", K(ret)); } } else if (is_hash_like_part(tablegroup_schema.get_part_option().get_part_func_type())) { @@ -2947,7 +2968,7 @@ int ObSchemaPrinter::print_individual_sub_partition_elements(const ObPartitionSc if (OB_ISNULL(schema) || OB_ISNULL(partition)) { ret = OB_INVALID_ARGUMENT; SHARE_SCHEMA_LOG(WARN, "argument is null", K(ret), K(schema), K(partition)); - } else if (schema->sub_part_template_def_valid()) { + } else if (!strict_compat_ && schema->sub_part_template_def_valid()) { ret = OB_INVALID_ARGUMENT; SHARE_SCHEMA_LOG(WARN, "schema is sub part template", K(ret)); } else if (OB_FAIL(schema->check_if_oracle_compat_mode(is_oracle_mode))) { @@ -2974,6 +2995,7 @@ int ObSchemaPrinter::print_list_partition_elements(const ObPartitionSchema *&sch char* buf, const int64_t& buf_len, int64_t& pos, + bool print_sub_part_element, bool agent_mode/*false*/, bool tablegroup_def/*false*/, const common::ObTimeZoneInfo *tz_info/*NULL*/) const @@ -2994,6 +3016,7 @@ int ObSchemaPrinter::print_list_partition_elements(const ObPartitionSchema *&sch SHARE_SCHEMA_LOG(WARN, "print enter failed", K(ret)); } else { int64_t part_num = schema->get_first_part_num(); + bool is_first = true; for (int64_t i = 0 ; OB_SUCC(ret) && i < part_num; ++i) { const ObPartition *partition = part_array[i]; if (OB_ISNULL(partition)) { @@ -3002,7 +3025,15 @@ int ObSchemaPrinter::print_list_partition_elements(const ObPartitionSchema *&sch } else { const ObString &part_name = partition->get_part_name(); bool print_collation = agent_mode && tablegroup_def; - if (OB_FAIL(databuff_printf(buf, buf_len, pos, "partition %.*s values %s (", + if (strict_compat_&& + partition->get_list_row_values().count() == 1 && + partition->get_list_row_values().at(0).get_count() == 1 && + partition->get_list_row_values().at(0).get_cell(0).is_max_value()) { + // default partition + // do nothing + } else if (!is_first && OB_FAIL(databuff_printf(buf, buf_len, pos, ",\n"))) { + SHARE_SCHEMA_LOG(WARN, "print enter failed", K(ret)); + } else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "partition %.*s values %s (", part_name.length(), part_name.ptr(), is_oracle_mode ? "" : "in"))) { @@ -3016,18 +3047,19 @@ int ObSchemaPrinter::print_list_partition_elements(const ObPartitionSchema *&sch } else if (OB_FAIL(print_tablespace_definition_for_table( partition->get_tenant_id(), partition->get_tablespace_id(), buf, buf_len, pos))) { SHARE_SCHEMA_LOG(WARN, "print tablespace definition failed", K(ret)); - } else if (!schema->sub_part_template_def_valid() + } else if (print_sub_part_element && OB_NOT_NULL(partition->get_subpart_array()) && OB_FAIL(print_individual_sub_partition_elements(schema, partition, buf, buf_len, pos, tz_info))) { SHARE_SCHEMA_LOG(WARN, "failed to print individual sub partition elements", K(ret)); - } else if (part_num - 1 != i && OB_FAIL(databuff_printf(buf, buf_len, pos, ",\n"))) { - SHARE_SCHEMA_LOG(WARN, "print enter failed", K(ret)); - } else if (part_num - 1 == i && OB_FAIL(databuff_printf(buf, buf_len, pos, ")"))) { - SHARE_SCHEMA_LOG(WARN, "print enter failed", K(ret)); - } else {} + } else { + is_first = false; + } } } + if (OB_SUCC(ret) && OB_FAIL(databuff_printf(buf, buf_len, pos, ")"))) { + SHARE_SCHEMA_LOG(WARN, "print enter failed", K(ret)); + } } } return ret; @@ -3037,6 +3069,7 @@ int ObSchemaPrinter::print_range_partition_elements(const ObPartitionSchema *&sc char* buf, const int64_t& buf_len, int64_t& pos, + bool print_sub_part_element, bool agent_mode, bool tablegroup_def, const common::ObTimeZoneInfo *tz_info) const @@ -3098,7 +3131,7 @@ int ObSchemaPrinter::print_range_partition_elements(const ObPartitionSchema *&sc if (OB_FAIL(print_tablespace_definition_for_table( partition->get_tenant_id(), partition->get_tablespace_id(), buf, buf_len, pos))) { SHARE_SCHEMA_LOG(WARN, "print tablespace id failed", K(ret), K(part_name)); - } else if (!schema->sub_part_template_def_valid() + } else if (print_sub_part_element && OB_NOT_NULL(partition->get_subpart_array()) && OB_FAIL(print_individual_sub_partition_elements(schema, partition, buf, buf_len, pos, tz_info))) { @@ -4670,6 +4703,7 @@ int ObSchemaPrinter::print_hash_partition_elements(const ObPartitionSchema *&sch char* buf, const int64_t& buf_len, int64_t& pos, + bool print_sub_part_element, bool agent_mode, const common::ObTimeZoneInfo *tz_info) const { @@ -4712,7 +4746,7 @@ int ObSchemaPrinter::print_hash_partition_elements(const ObPartitionSchema *&sch } else if (OB_FAIL(print_tablespace_definition_for_table( partition->get_tenant_id(), partition->get_tablespace_id(), buf, buf_len, pos))) { SHARE_SCHEMA_LOG(WARN, "print tablespace id failed", K(ret), K(part_name)); - } else if (!schema->sub_part_template_def_valid() + } else if (print_sub_part_element && OB_NOT_NULL(partition->get_subpart_array()) && OB_FAIL(print_individual_sub_partition_elements(schema, partition, buf, buf_len, pos, tz_info))) { diff --git a/src/share/schema/ob_schema_printer.h b/src/share/schema/ob_schema_printer.h index 41a4e6e02..99fd4c39e 100644 --- a/src/share/schema/ob_schema_printer.h +++ b/src/share/schema/ob_schema_printer.h @@ -17,6 +17,7 @@ #include "lib/container/ob_iarray.h" #include "share/schema/ob_schema_struct.h" #include "pl/parser/ob_pl_parser.h" +#include "share/schema/ob_table_schema.h" namespace oceanbase { @@ -54,7 +55,7 @@ class ObConstraint; class ObSchemaPrinter { public: - explicit ObSchemaPrinter(ObSchemaGetterGuard &schema_guard); + explicit ObSchemaPrinter(ObSchemaGetterGuard &schema_guard, bool strict_compat = false); virtual ~ObSchemaPrinter() { } private: ObSchemaPrinter(); @@ -255,6 +256,7 @@ public: char* buf, const int64_t& buf_len, int64_t& pos, + bool print_sub_part_element, bool agent_mode = false, bool tablegroup_def = false, const common::ObTimeZoneInfo *tz_info = NULL) const; @@ -262,6 +264,7 @@ public: char* buf, const int64_t& buf_len, int64_t& pos, + bool print_sub_part_element, bool agent_mode, bool tablegroup_def, const common::ObTimeZoneInfo *tz_info) const; @@ -441,10 +444,21 @@ public: char* buf, const int64_t& buf_len, int64_t& pos, + bool print_sub_part_element, bool agent_mode, const common::ObTimeZoneInfo *tz_info) const; private: + static bool is_subpartition_valid_in_mysql(const ObTableSchema &table_schema) + { + const ObPartitionOption &part_opt = table_schema.get_part_option(); + const ObPartitionOption &sub_part_opt = table_schema.get_sub_part_option(); + ObPartitionFuncType type = part_opt.get_part_func_type(); + ObPartitionFuncType sub_type = sub_part_opt.get_part_func_type(); + return is_hash_like_part(sub_type) && !is_hash_like_part(type); + } + ObSchemaGetterGuard &schema_guard_; + bool strict_compat_; }; diff --git a/src/share/system_variable/ob_sys_var_class_type.h b/src/share/system_variable/ob_sys_var_class_type.h index 2ee2797f0..9df7e511b 100644 --- a/src/share/system_variable/ob_sys_var_class_type.h +++ b/src/share/system_variable/ob_sys_var_class_type.h @@ -243,6 +243,7 @@ enum ObSysVarClassType SYS_VAR_OB_MAX_READ_STALE_TIME = 10137, SYS_VAR__OPTIMIZER_GATHER_STATS_ON_LOAD = 10138, SYS_VAR__SET_REVERSE_DBLINK_INFOS = 10139, + SYS_VAR__SHOW_DDL_IN_COMPAT_MODE = 10140, }; } diff --git a/src/share/system_variable/ob_system_variable_alias.h b/src/share/system_variable/ob_system_variable_alias.h index aedead1b8..3c365cbb8 100644 --- a/src/share/system_variable/ob_system_variable_alias.h +++ b/src/share/system_variable/ob_system_variable_alias.h @@ -238,6 +238,7 @@ namespace share static const char* const OB_SV_MAX_READ_STALE_TIME = "ob_max_read_stale_time"; static const char* const OB_SV__OPTIMIZER_GATHER_STATS_ON_LOAD = "_optimizer_gather_stats_on_load"; static const char* const OB_SV__SET_REVERSE_DBLINK_INFOS = "_set_reverse_dblink_infos"; + static const char* const OB_SV__SHOW_DDL_IN_COMPAT_MODE = "_show_ddl_in_compat_mode"; } } diff --git a/src/share/system_variable/ob_system_variable_factory.cpp b/src/share/system_variable/ob_system_variable_factory.cpp index cb021e19c..0a2827883 100644 --- a/src/share/system_variable/ob_system_variable_factory.cpp +++ b/src/share/system_variable/ob_system_variable_factory.cpp @@ -146,6 +146,7 @@ const char *ObSysVarFactory::SYS_VAR_NAMES_SORTED_BY_NAME[] = { "_set_purge_job_interval", "_set_purge_job_status", "_set_reverse_dblink_infos", + "_show_ddl_in_compat_mode", "_windowfunc_optimization_settings", "auto_increment_cache_size", "auto_increment_increment", @@ -371,6 +372,7 @@ const ObSysVarClassType ObSysVarFactory::SYS_VAR_IDS_SORTED_BY_NAME[] = { SYS_VAR__SET_PURGE_JOB_INTERVAL, SYS_VAR__SET_PURGE_JOB_STATUS, SYS_VAR__SET_REVERSE_DBLINK_INFOS, + SYS_VAR__SHOW_DDL_IN_COMPAT_MODE, SYS_VAR__WINDOWFUNC_OPTIMIZATION_SETTINGS, SYS_VAR_AUTO_INCREMENT_CACHE_SIZE, SYS_VAR_AUTO_INCREMENT_INCREMENT, @@ -789,7 +791,8 @@ const char *ObSysVarFactory::SYS_VAR_NAMES_SORTED_BY_ID[] = { "log_row_value_options", "ob_max_read_stale_time", "_optimizer_gather_stats_on_load", - "_set_reverse_dblink_infos" + "_set_reverse_dblink_infos", + "_show_ddl_in_compat_mode" }; bool ObSysVarFactory::sys_var_name_case_cmp(const char *name1, const ObString &name2) @@ -1179,6 +1182,7 @@ int ObSysVarFactory::create_all_sys_vars() + sizeof(ObSysVarObMaxReadStaleTime) + sizeof(ObSysVarOptimizerGatherStatsOnLoad) + sizeof(ObSysVarSetReverseDblinkInfos) + + sizeof(ObSysVarShowDdlInCompatMode) ; void *ptr = NULL; if (OB_ISNULL(ptr = allocator_.alloc(total_mem_size))) { @@ -3185,6 +3189,15 @@ int ObSysVarFactory::create_all_sys_vars() ptr = (void *)((char *)ptr + sizeof(ObSysVarSetReverseDblinkInfos)); } } + if (OB_SUCC(ret)) { + if (OB_ISNULL(sys_var_ptr = new (ptr)ObSysVarShowDdlInCompatMode())) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_ERROR("fail to new ObSysVarShowDdlInCompatMode", K(ret)); + } else { + store_buf_[ObSysVarsToIdxMap::get_store_idx(static_cast(SYS_VAR__SHOW_DDL_IN_COMPAT_MODE))] = sys_var_ptr; + ptr = (void *)((char *)ptr + sizeof(ObSysVarShowDdlInCompatMode)); + } + } } return ret; @@ -5653,6 +5666,17 @@ int ObSysVarFactory::create_sys_var(ObSysVarClassType sys_var_id, ObBasicSysVar } break; } + case SYS_VAR__SHOW_DDL_IN_COMPAT_MODE: { + void *ptr = NULL; + if (OB_ISNULL(ptr = allocator_.alloc(sizeof(ObSysVarShowDdlInCompatMode)))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_ERROR("fail to alloc memory", K(ret), K(sizeof(ObSysVarShowDdlInCompatMode))); + } else if (OB_ISNULL(sys_var_ptr = new (ptr)ObSysVarShowDdlInCompatMode())) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_ERROR("fail to new ObSysVarShowDdlInCompatMode", K(ret)); + } + break; + } default: { ret = OB_ERR_UNEXPECTED; diff --git a/src/share/system_variable/ob_system_variable_factory.h b/src/share/system_variable/ob_system_variable_factory.h index 67af273d1..c5e1fa02c 100644 --- a/src/share/system_variable/ob_system_variable_factory.h +++ b/src/share/system_variable/ob_system_variable_factory.h @@ -1605,6 +1605,13 @@ public: inline virtual ObSysVarClassType get_type() const { return SYS_VAR__SET_REVERSE_DBLINK_INFOS; } inline virtual const common::ObObj &get_global_default_value() const { return ObSysVariables::get_default_value(221); } }; +class ObSysVarShowDdlInCompatMode : public ObBoolSysVar +{ +public: + ObSysVarShowDdlInCompatMode() : ObBoolSysVar(NULL, NULL, NULL, NULL, NULL) {} + inline virtual ObSysVarClassType get_type() const { return SYS_VAR__SHOW_DDL_IN_COMPAT_MODE; } + inline virtual const common::ObObj &get_global_default_value() const { return ObSysVariables::get_default_value(222); } +}; class ObSysVarFactory @@ -1624,7 +1631,7 @@ public: static const common::ObString get_sys_var_name_by_id(ObSysVarClassType sys_var_id); const static int64_t MYSQL_SYS_VARS_COUNT = 97; - const static int64_t OB_SYS_VARS_COUNT = 125; + const static int64_t OB_SYS_VARS_COUNT = 126; const static int64_t ALL_SYS_VARS_COUNT = MYSQL_SYS_VARS_COUNT + OB_SYS_VARS_COUNT; const static int16_t OB_SPECIFIC_SYS_VAR_ID_OFFSET = 10000; diff --git a/src/share/system_variable/ob_system_variable_init.cpp b/src/share/system_variable/ob_system_variable_init.cpp index ff1e53f88..f352aea87 100644 --- a/src/share/system_variable/ob_system_variable_init.cpp +++ b/src/share/system_variable/ob_system_variable_init.cpp @@ -2915,13 +2915,25 @@ static struct VarsInit{ ObSysVars[221].alias_ = "OB_SV__SET_REVERSE_DBLINK_INFOS" ; }(); + [&] (){ + ObSysVars[222].info_ = "When enabled, show create table will show the strict compatible results with the compatibility mode." ; + ObSysVars[222].name_ = "_show_ddl_in_compat_mode" ; + ObSysVars[222].data_type_ = ObIntType ; + ObSysVars[222].value_ = "0" ; + ObSysVars[222].flags_ = ObSysVarFlag::SESSION_SCOPE ; + ObSysVars[222].id_ = SYS_VAR__SHOW_DDL_IN_COMPAT_MODE ; + cur_max_var_id = MAX(cur_max_var_id, static_cast(SYS_VAR__SHOW_DDL_IN_COMPAT_MODE)) ; + ObSysVarsIdToArrayIdx[SYS_VAR__SHOW_DDL_IN_COMPAT_MODE] = 222 ; + ObSysVars[222].alias_ = "OB_SV__SHOW_DDL_IN_COMPAT_MODE" ; + }(); + if (cur_max_var_id >= ObSysVarFactory::OB_MAX_SYS_VAR_ID) { HasInvalidSysVar = true; } } }vars_init; -static int64_t var_amount = 222; +static int64_t var_amount = 223; int64_t ObSysVariables::get_all_sys_var_count(){ return ObSysVarFactory::ALL_SYS_VARS_COUNT;} ObSysVarClassType ObSysVariables::get_sys_var_id(int64_t i){ return ObSysVars[i].id_;} diff --git a/src/share/system_variable/ob_system_variable_init.json b/src/share/system_variable/ob_system_variable_init.json index c2fcd831e..c8a722cda 100644 --- a/src/share/system_variable/ob_system_variable_init.json +++ b/src/share/system_variable/ob_system_variable_init.json @@ -2944,5 +2944,17 @@ "info_cn": "用于dblink写事务中, TM端通过设置系统变量的方式告知RM端关于建立反向dblink的必要信息", "background_cn": "", "ref_url": "" + }, + "_show_ddl_in_compat_mode": { + "id": 10140, + "name": "_show_ddl_in_compat_mode", + "value": "0", + "data_type": "bool", + "info": "When enabled, show create table will show the strict compatible results with the compatibility mode.", + "flags": "SESSION", + "publish_version": "324", + "info_cn": "启用后, show create table 将展示与兼容模式严格兼容的结果", + "background_cn": "", + "ref_url": "/" } } diff --git a/src/sql/session/ob_basic_session_info.cpp b/src/sql/session/ob_basic_session_info.cpp index 0ce1c0981..2081e7eff 100644 --- a/src/sql/session/ob_basic_session_info.cpp +++ b/src/sql/session/ob_basic_session_info.cpp @@ -3383,6 +3383,11 @@ int ObBasicSessionInfo::get_net_buffer_length(int64_t &net_buffer_len) const return get_int64_sys_var(SYS_VAR_NET_BUFFER_LENGTH, net_buffer_len); } +int ObBasicSessionInfo::get_show_ddl_in_compat_mode(bool &show_ddl_in_compat_mode) const +{ + return get_bool_sys_var(SYS_VAR__SHOW_DDL_IN_COMPAT_MODE, show_ddl_in_compat_mode); +} + //////////////////////////////////////////////////////////////// int ObBasicSessionInfo::replace_user_variables(const ObSessionValMap &user_var_map) { diff --git a/src/sql/session/ob_basic_session_info.h b/src/sql/session/ob_basic_session_info.h index 4c6830177..9fda507fa 100644 --- a/src/sql/session/ob_basic_session_info.h +++ b/src/sql/session/ob_basic_session_info.h @@ -492,6 +492,7 @@ public: is_result_accurate = sys_vars_cache_.get_is_result_accurate(); return common::OB_SUCCESS; } + int get_show_ddl_in_compat_mode(bool &show_ddl_in_compat_mode) const; common::ObConsistencyLevel get_consistency_level() const { return consistency_level_; }; bool is_zombie() const { return SESSION_KILLED == get_session_state();} bool is_query_killed() const;