From 5991a385e1bba1bb844c67eec92fbc39d75bbdd9 Mon Sep 17 00:00:00 2001 From: xianyu-w <707512433@qq.com> Date: Tue, 30 May 2023 03:17:44 +0000 Subject: [PATCH] [CP] Fix show create database bug when enable _show_ddl_in_compat_mode --- .../virtual_table/ob_show_create_database.cpp | 13 +++++++++---- src/share/schema/ob_schema_printer.cpp | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/observer/virtual_table/ob_show_create_database.cpp b/src/observer/virtual_table/ob_show_create_database.cpp index dbff72fdec..73863a16a1 100644 --- a/src/observer/virtual_table/ob_show_create_database.cpp +++ b/src/observer/virtual_table/ob_show_create_database.cpp @@ -14,6 +14,7 @@ #include "observer/virtual_table/ob_show_create_database.h" #include "share/schema/ob_schema_getter_guard.h" #include "share/schema/ob_schema_printer.h" +#include "sql/session/ob_sql_session_info.h" using namespace oceanbase::common; using namespace oceanbase::share::schema; @@ -108,11 +109,13 @@ int ObShowCreateDatabase::fill_row_cells(uint64_t show_database_id, const ObString &database_name) { int ret = OB_SUCCESS; + bool strict_mode = false; if (OB_ISNULL(cur_row_.cells_) || OB_ISNULL(schema_guard_) - || OB_ISNULL(allocator_)) { + || OB_ISNULL(allocator_) + || OB_ISNULL(session_)) { ret = OB_NOT_INIT; - LOG_WARN("class isn't inited", K(cur_row_.cells_), K(schema_guard_), K(allocator_)); + LOG_WARN("class isn't inited", K(cur_row_.cells_), K(schema_guard_), K(allocator_), K(session_)); } else if (OB_UNLIKELY(cur_row_.count_ < output_column_ids_.count())) { ret = OB_ERR_UNEXPECTED; SERVER_LOG(WARN, @@ -120,6 +123,8 @@ int ObShowCreateDatabase::fill_row_cells(uint64_t show_database_id, K(ret), K(cur_row_.count_), K(output_column_ids_.count())); + } 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 { uint64_t cell_idx = 0; char *db_def_buf = NULL; @@ -145,7 +150,7 @@ int ObShowCreateDatabase::fill_row_cells(uint64_t show_database_id, } case OB_APP_MIN_COLUMN_ID + 2: { // create_database - ObSchemaPrinter schema_printer(*schema_guard_); + ObSchemaPrinter schema_printer(*schema_guard_, strict_mode); int64_t pos = 0; if (OB_FAIL(schema_printer.print_database_definiton(effective_tenant_id_, show_database_id, @@ -166,7 +171,7 @@ int ObShowCreateDatabase::fill_row_cells(uint64_t show_database_id, } case OB_APP_MIN_COLUMN_ID + 3: { // create_database_with_if_not_exists - ObSchemaPrinter schema_printer(*schema_guard_); + ObSchemaPrinter schema_printer(*schema_guard_, strict_mode); int64_t pos = 0; if (OB_FAIL(schema_printer.print_database_definiton(effective_tenant_id_, show_database_id, diff --git a/src/share/schema/ob_schema_printer.cpp b/src/share/schema/ob_schema_printer.cpp index 27f033adb0..cfe18751d3 100644 --- a/src/share/schema/ob_schema_printer.cpp +++ b/src/share/schema/ob_schema_printer.cpp @@ -3202,7 +3202,7 @@ int ObSchemaPrinter::print_database_definiton( SHARE_SCHEMA_LOG(WARN, "fail to print default collate", K(ret), K(*database_schema)); } } - if (OB_SUCC(ret)) { + if (OB_SUCC(ret) && !strict_compat_) { int64_t paxos_replica_num = OB_INVALID_COUNT; if (OB_FAIL(database_schema->get_paxos_replica_num(schema_guard_, paxos_replica_num))) { LOG_WARN("fail to get paxos replica num", K(ret)); @@ -3215,12 +3215,12 @@ int ObSchemaPrinter::print_database_definiton( } else {} // no more to do } - if (OB_SUCC(ret) && database_schema->is_read_only()) { + if (OB_SUCC(ret) && !strict_compat_ && database_schema->is_read_only()) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, " READ ONLY"))) { SHARE_SCHEMA_LOG(WARN, "fail to print database read only", K(ret)); } } - if (OB_SUCC(ret)) { + if (OB_SUCC(ret) && !strict_compat_) { uint64_t tablegroup_id = database_schema->get_default_tablegroup_id(); if (common::OB_INVALID_ID != tablegroup_id) { const ObTablegroupSchema *tablegroup_schema = schema_guard_.get_tablegroup_schema(