From 7fb21bbbe7fde0cb2007e88fe184d767511c59e7 Mon Sep 17 00:00:00 2001 From: bf0 Date: Wed, 21 Jul 2021 23:46:35 +0800 Subject: [PATCH] cherry-pick bug fix in 3.1 --- deps/oblib/src/lib/charset/ob_charset.cpp | 20 ++- deps/oblib/src/lib/charset/ob_charset.h | 5 +- .../src/lib/timezone/ob_time_convert.cpp | 9 +- src/observer/ob_inner_sql_connection.cpp | 2 +- .../ob_inner_table_schema.25001_25050.cpp | 6 +- .../inner_table/ob_inner_table_schema_def.py | 61 +++++-- src/share/object/ob_obj_cast.cpp | 2 + src/sql/engine/cmd/ob_load_data_impl.cpp | 104 ++++++----- src/sql/engine/cmd/ob_load_data_impl.h | 3 +- src/sql/engine/cmd/ob_load_data_rpc.cpp | 16 +- src/sql/engine/cmd/ob_load_data_rpc.h | 16 +- .../engine/expr/ob_expr_eval_functions.cpp | 6 +- .../engine/expr/ob_expr_result_type_util.cpp | 6 +- src/sql/engine/expr/ob_expr_to_multi_byte.cpp | 139 ++++++++++----- src/sql/engine/expr/ob_expr_to_multi_byte.h | 12 +- .../engine/expr/ob_expr_to_single_byte.cpp | 168 ++++++++++++------ src/sql/engine/expr/ob_expr_to_single_byte.h | 11 +- src/sql/ob_sql_utils.cpp | 36 +++- src/sql/ob_sql_utils.h | 2 +- .../resolver/expr/ob_raw_expr_deduce_type.cpp | 5 +- src/sql/session/ob_basic_session_info.h | 3 +- src/storage/compaction/ob_partition_merge.cpp | 3 +- src/storage/ob_partition_storage.cpp | 23 ++- 23 files changed, 450 insertions(+), 208 deletions(-) diff --git a/deps/oblib/src/lib/charset/ob_charset.cpp b/deps/oblib/src/lib/charset/ob_charset.cpp index 8fe3eecd28..9eaa04268f 100644 --- a/deps/oblib/src/lib/charset/ob_charset.cpp +++ b/deps/oblib/src/lib/charset/ob_charset.cpp @@ -2397,5 +2397,21 @@ int ObStringScanner::next_character(ObString& encoding, int32_t& wchar) return ret; } -} // namespace common -} // namespace oceanbase +bool ObStringScanner::next_character(ObString &encoding, int32_t &wchar, int &ret) +{ + bool has_next = false; + ret = next_character(encoding, wchar); + if (OB_ITER_END == ret) { + has_next = false; + ret = OB_SUCCESS; + } else if (OB_SUCC(ret)) { + has_next = true; + } else { + LOG_WARN("fail to get next character", K(ret), K(*this)); + has_next = false; + } + return has_next; +} + +} // namespace common +} // namespace oceanbase diff --git a/deps/oblib/src/lib/charset/ob_charset.h b/deps/oblib/src/lib/charset/ob_charset.h index 542a0a4ed0..4e9acbafe5 100644 --- a/deps/oblib/src/lib/charset/ob_charset.h +++ b/deps/oblib/src/lib/charset/ob_charset.h @@ -93,6 +93,8 @@ private: virtual ~ObCharset(){}; public: + static const int32_t MAX_MB_LEN = 5; + static const int32_t MIN_MB_LEN = 1; static const int64_t CHARSET_WRAPPER_COUNT = 2; static const int64_t COLLATION_WRAPPER_COUNT = 3; @@ -306,7 +308,8 @@ public: ObStringScanner(const ObString& str, common::ObCollationType collation_type) : str_(str), collation_type_(collation_type) {} - int next_character(ObString& encoding, int32_t& wchar); + int next_character(ObString &encoding, int32_t &wchar); + bool next_character(ObString &encoding, int32_t &wchar, int &ret); TO_STRING_KV(K_(str), K_(collation_type)); private: diff --git a/deps/oblib/src/lib/timezone/ob_time_convert.cpp b/deps/oblib/src/lib/timezone/ob_time_convert.cpp index c5e2076c26..57dbb7e7f5 100644 --- a/deps/oblib/src/lib/timezone/ob_time_convert.cpp +++ b/deps/oblib/src/lib/timezone/ob_time_convert.cpp @@ -3183,16 +3183,13 @@ int ObTimeConverter::str_to_ob_time_oracle_dfm( // 2. set default value for ob_time if (OB_SUCC(ret)) { int64_t utc_curr_time = ObTimeUtility::current_time(); + int64_t utc_curr_time_copy = utc_curr_time; int32_t cur_date = 0; if (OB_ISNULL(cvrt_ctx.tz_info_)) { ret = OB_ERR_UNEXPECTED; LOG_WARN("session timezone info is null", K(ret)); - } else if (sub_timezone_offset(*(cvrt_ctx.tz_info_), - ObString(), - utc_curr_time, - session_tz_offset, - session_tz_id, - session_tran_type_id)) { + } else if (sub_timezone_offset(*(cvrt_ctx.tz_info_), ObString(), + utc_curr_time_copy, session_tz_offset, session_tz_id, session_tran_type_id)) { LOG_WARN("get session timezone offset failed", K(ret)); } else if (OB_FAIL(datetime_to_date(utc_curr_time, cvrt_ctx.tz_info_, cur_date))) { LOG_WARN("timestamp to date failed", K(ret)); diff --git a/src/observer/ob_inner_sql_connection.cpp b/src/observer/ob_inner_sql_connection.cpp index 4883780906..cabc43b34c 100644 --- a/src/observer/ob_inner_sql_connection.cpp +++ b/src/observer/ob_inner_sql_connection.cpp @@ -411,7 +411,7 @@ int ObInnerSQLConnection::process_retry( is_get_location_timeout_error(last_ret) || is_try_lock_row_err(last_ret) || is_has_no_readable_replica_err(last_ret) || is_select_dup_follow_replic_err(last_ret) || is_trans_stmt_need_retry_error(last_ret) || is_transaction_set_violation_err(last_ret) || - is_snapshot_discarded_err(last_ret))) { + is_snapshot_discarded_err(last_ret) || OB_AUTOINC_SERVICE_BUSY == last_ret)) { need_retry = true; const uint64_t* trace_id = ObCurTraceId::get(); bool sql_trigger_by_user_req = (NULL != trace_id && 0 != trace_id[0] && 0 != trace_id[1]); diff --git a/src/share/inner_table/ob_inner_table_schema.25001_25050.cpp b/src/share/inner_table/ob_inner_table_schema.25001_25050.cpp index 437539aa9e..14dc18c14e 100644 --- a/src/share/inner_table/ob_inner_table_schema.25001_25050.cpp +++ b/src/share/inner_table/ob_inner_table_schema.25001_25050.cpp @@ -944,7 +944,7 @@ int ObInnerTableSchema::all_tab_cols_v_schema(ObTableSchema &table_schema) table_schema.set_create_mem_version(1); if (OB_SUCC(ret)) { - if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT cast(db.database_name as VARCHAR2(128)) as OWNER, cast(t.table_name as VARCHAR2(128)) as TABLE_NAME, cast(c.column_name as VARCHAR2(128)) as COLUMN_NAME, cast(decode(c.data_type, 0, 'NULL', 1, 'NUMBER', 2, 'NUMBER', 3, 'NUMBER', 4, 'NUMBER', 5, 'NUMBER', 6, 'NUMBER', 7, 'NUMBER', 8, 'NUMBER', 9, 'NUMBER', 10, 'NUMBER', 11, 'BINARY_FLOAT', 12, 'BINARY_DOUBLE', 13, 'NUMBER', 14, 'NUMBER', 15, 'NUMBER', 16, 'NUMBER', 17, 'DATE', 18, 'TIMESTAMP', 19, 'DATE', 20, 'TIME', 21, 'YEAR', 22, 'VARCHAR2', 23, 'CHAR', 24, 'HEX_STRING', 25, 'EXT', 26, 'UNKNOWN', 27, 'TINYTEXT', 28, 'TEXT', 29, 'MEDIUMTEXT', 30, decode(c.collation_type, 63, 'BLOB', 'CLOB'), 31, 'BIT', 32, 'ENUM', 33, 'SET', 34, 'ENUM_INNER', 35, 'SET_INNER', 36, concat('TIMESTAMP(', concat(c.data_scale, ') WITH TIME ZONE')), 37, concat('TIMESTAMP(', concat(c.data_scale, ') WITH LOCAL TIME ZONE')), 38, concat('TIMESTAMP(', concat(c.data_scale, ')')), 39, 'RAW', 40, concat('INTERVAL YEAR(', concat(c.data_scale, ') TO MONTH')), 41, concat('INTERVAL DAY(', concat(trunc(c.data_scale/10), concat(') TO SECOND(', concat(mod(c.data_scale, 10), ')')))), 42, 'FLOAT', 43, 'NVARCHAR2', 44, 'NCHAR', 45, 'UROWID', 46, '', 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, cast(c.data_length as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END END as NUMBER) as DATA_PRECISION, cast(CASE WHEN c.data_type in (11,12,17,19,22,23,27,28,29,30,42,43,44) THEN NULL ELSE CASE WHEN c.data_scale < -84 THEN NULL ELSE c.data_scale END END as NUMBER) as DATA_SCALE, cast(decode(c.nullable, 1, 'Y', 'N') as VARCHAR2(1)) as NULLABLE, cast(decode(BITAND(c.column_flags, 64), 0, c.column_id, NULL) as NUMBER) as COLUMN_ID, cast(LENGTHB(c.cur_default_value_v2) as NUMBER) as DEFAULT_LENGTH, cast(c.cur_default_value_v2 as /* TODO: LONG() */ VARCHAR(128)) as DATA_DEFAULT, cast(NULL as NUMBER) as NUM_DISTINCT, cast(NULL as /* TODO: RAW */ varchar(128)) as LOW_VALUE, cast(NULL as /* TODO: RAW */ varchar(128)) as HIGH_VALUE, cast(NULL as NUMBER) as DENSITY, cast(NULL as NUMBER) as NUM_NULLS, cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, cast(NULL as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, cast(decode(c.data_type, 22, c.data_length, 23, c.data_length, 0) as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, cast(decode(BITAND(c.column_flags, 64), 0, 'NO', 'YES') as VARCHAR2(3)) as HIDDEN_COLUMN, cast(decode(BITAND(c.column_flags, 1), 1, 'YES', 'NO') as VARCHAR2(3)) as VIRTUAL_COLUMN, cast(NULL as NUMBER) as SEGMENT_COLUMN_ID, cast(NULL as NUMBER) as INTERNAL_COLUMN_ID, cast(NULL as VARCHAR2(15)) as HISTOGRAM, cast(c.column_name as VARCHAR2(4000)) as QUALIFIED_COL_NAME, cast('YES' as VARCHAR2(3)) as USER_GENERATED, cast(NULL as VARCHAR2(3)) as DEFAULT_ON_NULL, cast(NULL as VARCHAR2(3)) as IDENTITY_COLUMN, cast(NULL as VARCHAR2(128)) as EVALUATION_EDITION, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEFORE, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEGINNING, cast(NULL as VARCHAR2(100)) as COLLATION, cast(NULL as NUMBER) as COLLATED_COLUMN_ID FROM sys.ALL_VIRTUAL_TABLE_REAL_AGENT t JOIN sys.ALL_VIRTUAL_DATABASE_REAL_AGENT db ON db.tenant_id = t.tenant_id AND db.database_id = t.database_id AND (t.database_id = userenv('SCHEMAID') OR user_can_access_obj(1, t.table_id, t.database_id) = 1) AND T.TENANT_ID = EFFECTIVE_TENANT_ID() AND DB.TENANT_ID = EFFECTIVE_TENANT_ID() JOIN sys.ALL_VIRTUAL_COLUMN_REAL_AGENT c ON c.tenant_id = t.tenant_id AND c.table_id = t.table_id AND C.TENANT_ID = EFFECTIVE_TENANT_ID() WHERE c.is_hidden = 0 AND t.table_type in (0,2,3,8,9) )__"))) { + if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT cast(db.database_name as VARCHAR2(128)) as OWNER, cast(t.table_name as VARCHAR2(128)) as TABLE_NAME, cast(c.column_name as VARCHAR2(128)) as COLUMN_NAME, cast(decode(c.data_type, 0, 'NULL', 1, 'NUMBER', 2, 'NUMBER', 3, 'NUMBER', 4, 'NUMBER', 5, 'NUMBER', 6, 'NUMBER', 7, 'NUMBER', 8, 'NUMBER', 9, 'NUMBER', 10, 'NUMBER', 11, 'BINARY_FLOAT', 12, 'BINARY_DOUBLE', 13, 'NUMBER', 14, 'NUMBER', 15, 'NUMBER', 16, 'NUMBER', 17, 'DATE', 18, 'TIMESTAMP', 19, 'DATE', 20, 'TIME', 21, 'YEAR', 22, 'VARCHAR2', 23, 'CHAR', 24, 'HEX_STRING', 25, 'EXT', 26, 'UNKNOWN', 27, 'TINYTEXT', 28, 'TEXT', 29, 'MEDIUMTEXT', 30, decode(c.collation_type, 63, 'BLOB', 'CLOB'), 31, 'BIT', 32, 'ENUM', 33, 'SET', 34, 'ENUM_INNER', 35, 'SET_INNER', 36, concat('TIMESTAMP(', concat(c.data_scale, ') WITH TIME ZONE')), 37, concat('TIMESTAMP(', concat(c.data_scale, ') WITH LOCAL TIME ZONE')), 38, concat('TIMESTAMP(', concat(c.data_scale, ')')), 39, 'RAW', 40, concat('INTERVAL YEAR(', concat(c.data_scale, ') TO MONTH')), 41, concat('INTERVAL DAY(', concat(trunc(c.data_scale/10), concat(') TO SECOND(', concat(mod(c.data_scale, 10), ')')))), 42, 'FLOAT', 43, 'NVARCHAR2', 44, 'NCHAR', 45, 'UROWID', 46, '', 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, cast(c.data_length * CASE WHEN c.data_type in (22,23,30,43,44,46) and c.data_precision = 1 THEN decode(c.collation_type, 63, 1, 249, 4, 248, 4, 87, 2, 28, 2, 55, 4, 54, 4, 101, 2, 46, 4, 45, 4, 224, 4, 1) ELSE 1 END as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END END as NUMBER) as DATA_PRECISION, cast(CASE WHEN c.data_type in (11,12,17,19,22,23,27,28,29,30,42,43,44) THEN NULL ELSE CASE WHEN c.data_scale < -84 THEN NULL ELSE c.data_scale END END as NUMBER) as DATA_SCALE, cast(decode(c.nullable, 1, 'Y', 'N') as VARCHAR2(1)) as NULLABLE, cast(decode(BITAND(c.column_flags, 64), 0, c.column_id, NULL) as NUMBER) as COLUMN_ID, cast(LENGTHB(c.cur_default_value_v2) as NUMBER) as DEFAULT_LENGTH, cast(c.cur_default_value_v2 as /* TODO: LONG() */ VARCHAR(128)) as DATA_DEFAULT, cast(NULL as NUMBER) as NUM_DISTINCT, cast(NULL as /* TODO: RAW */ varchar(128)) as LOW_VALUE, cast(NULL as /* TODO: RAW */ varchar(128)) as HIGH_VALUE, cast(NULL as NUMBER) as DENSITY, cast(NULL as NUMBER) as NUM_NULLS, cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, cast(decode(c.data_type, 22, 'CHAR_CS', 23, 'CHAR_CS', 30, decode(c.collation_type, 63, 'NULL', 'CHAR_CS'), 43, 'NCHAR_CS', 44, 'NCHAR_CS', '') as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, cast(CASE WHEN c.data_type in (22,23,43,44) THEN c.data_length ELSE 0 END as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), 43, decode(c.data_precision, 1, 'C', 'B'), 44, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, cast(decode(BITAND(c.column_flags, 64), 0, 'NO', 'YES') as VARCHAR2(3)) as HIDDEN_COLUMN, cast(decode(BITAND(c.column_flags, 1), 1, 'YES', 'NO') as VARCHAR2(3)) as VIRTUAL_COLUMN, cast(NULL as NUMBER) as SEGMENT_COLUMN_ID, cast(NULL as NUMBER) as INTERNAL_COLUMN_ID, cast(NULL as VARCHAR2(15)) as HISTOGRAM, cast(c.column_name as VARCHAR2(4000)) as QUALIFIED_COL_NAME, cast('YES' as VARCHAR2(3)) as USER_GENERATED, cast(NULL as VARCHAR2(3)) as DEFAULT_ON_NULL, cast(NULL as VARCHAR2(3)) as IDENTITY_COLUMN, cast(NULL as VARCHAR2(128)) as EVALUATION_EDITION, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEFORE, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEGINNING, cast(NULL as VARCHAR2(100)) as COLLATION, cast(NULL as NUMBER) as COLLATED_COLUMN_ID FROM sys.ALL_VIRTUAL_TABLE_REAL_AGENT t JOIN sys.ALL_VIRTUAL_DATABASE_REAL_AGENT db ON db.tenant_id = t.tenant_id AND db.database_id = t.database_id AND (t.database_id = userenv('SCHEMAID') OR user_can_access_obj(1, t.table_id, t.database_id) = 1) AND T.TENANT_ID = EFFECTIVE_TENANT_ID() AND DB.TENANT_ID = EFFECTIVE_TENANT_ID() JOIN sys.ALL_VIRTUAL_COLUMN_REAL_AGENT c ON c.tenant_id = t.tenant_id AND c.table_id = t.table_id AND C.TENANT_ID = EFFECTIVE_TENANT_ID() WHERE c.is_hidden = 0 AND t.table_type in (0,2,3,8,9) )__"))) { LOG_ERROR("fail to set view_definition", K(ret)); } } @@ -996,7 +996,7 @@ int ObInnerTableSchema::dba_tab_cols_v_schema(ObTableSchema &table_schema) table_schema.set_create_mem_version(1); if (OB_SUCC(ret)) { - if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT cast(db.database_name as VARCHAR2(128)) as OWNER, cast(t.table_name as VARCHAR2(128)) as TABLE_NAME, cast(c.column_name as VARCHAR2(128)) as COLUMN_NAME, cast(decode(c.data_type, 0, 'NULL', 1, 'NUMBER', 2, 'NUMBER', 3, 'NUMBER', 4, 'NUMBER', 5, 'NUMBER', 6, 'NUMBER', 7, 'NUMBER', 8, 'NUMBER', 9, 'NUMBER', 10, 'NUMBER', 11, 'BINARY_FLOAT', 12, 'BINARY_DOUBLE', 13, 'NUMBER', 14, 'NUMBER', 15, 'NUMBER', 16, 'NUMBER', 17, 'DATE', 18, 'TIMESTAMP', 19, 'DATE', 20, 'TIME', 21, 'YEAR', 22, 'VARCHAR2', 23, 'CHAR', 24, 'HEX_STRING', 25, 'EXT', 26, 'UNKNOWN', 27, 'TINYTEXT', 28, 'TEXT', 29, 'MEDIUMTEXT', 30, decode(c.collation_type, 63, 'BLOB', 'CLOB'), 31, 'BIT', 32, 'ENUM', 33, 'SET', 34, 'ENUM_INNER', 35, 'SET_INNER', 36, concat('TIMESTAMP(', concat(c.data_scale, ') WITH TIME ZONE')), 37, concat('TIMESTAMP(', concat(c.data_scale, ') WITH LOCAL TIME ZONE')), 38, concat('TIMESTAMP(', concat(c.data_scale, ')')), 39, 'RAW', 40, concat('INTERVAL YEAR(', concat(c.data_scale, ') TO MONTH')), 41, concat('INTERVAL DAY(', concat(trunc(c.data_scale/10), concat(') TO SECOND(', concat(mod(c.data_scale, 10), ')')))), 42, 'FLOAT', 43, 'NVARCHAR2', 44, 'NCHAR', 45, '', 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, cast(c.data_length as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END END as NUMBER) as DATA_PRECISION, cast(CASE WHEN c.data_type in (11,12,17,19,22,23,27,28,29,30,42,43,44) THEN NULL ELSE CASE WHEN c.data_scale < -84 THEN NULL ELSE c.data_scale END END as NUMBER) as DATA_SCALE, cast(decode(c.nullable, 1, 'Y', 'N') as VARCHAR2(1)) as NULLABLE, cast(decode(BITAND(c.column_flags, 64), 0, c.column_id, NULL) as NUMBER) as COLUMN_ID, cast(LENGTHB(c.cur_default_value_v2) as NUMBER) as DEFAULT_LENGTH, cast(c.cur_default_value_v2 as /* TODO: LONG() */ VARCHAR(128)) as DATA_DEFAULT, cast(NULL as NUMBER) as NUM_DISTINCT, cast(NULL as /* TODO: RAW */ varchar(128)) as LOW_VALUE, cast(NULL as /* TODO: RAW */ varchar(128)) as HIGH_VALUE, cast(NULL as NUMBER) as DENSITY, cast(NULL as NUMBER) as NUM_NULLS, cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, cast(NULL as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, cast(decode(c.data_type, 22, c.data_length, 23, c.data_length, 0) as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, cast(decode(BITAND(c.column_flags, 64), 0, 'NO', 'YES') as VARCHAR2(3)) as HIDDEN_COLUMN, cast(decode(BITAND(c.column_flags, 1), 1, 'YES', 'NO') as VARCHAR2(3)) as VIRTUAL_COLUMN, cast(NULL as NUMBER) as SEGMENT_COLUMN_ID, cast(NULL as NUMBER) as INTERNAL_COLUMN_ID, cast(NULL as VARCHAR2(15)) as HISTOGRAM, cast(c.column_name as VARCHAR2(4000)) as QUALIFIED_COL_NAME, cast('YES' as VARCHAR2(3)) as USER_GENERATED, cast(NULL as VARCHAR2(3)) as DEFAULT_ON_NULL, cast(NULL as VARCHAR2(3)) as IDENTITY_COLUMN, cast(NULL as VARCHAR2(128)) as EVALUATION_EDITION, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEFORE, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEGINNING, cast(NULL as VARCHAR2(100)) as COLLATION, cast(NULL as NUMBER) as COLLATED_COLUMN_ID FROM sys.ALL_VIRTUAL_TABLE_REAL_AGENT t JOIN sys.ALL_VIRTUAL_DATABASE_REAL_AGENT db ON db.tenant_id = t.tenant_id AND db.database_id = t.database_id AND T.TENANT_ID = EFFECTIVE_TENANT_ID() AND DB.TENANT_ID = EFFECTIVE_TENANT_ID() JOIN sys.ALL_VIRTUAL_COLUMN_REAL_AGENT c ON c.tenant_id = t.tenant_id AND c.table_id = t.table_id AND C.TENANT_ID = EFFECTIVE_TENANT_ID() WHERE c.is_hidden = 0 AND t.table_type in (0,2,3,8,9) )__"))) { + if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT cast(db.database_name as VARCHAR2(128)) as OWNER, cast(t.table_name as VARCHAR2(128)) as TABLE_NAME, cast(c.column_name as VARCHAR2(128)) as COLUMN_NAME, cast(decode(c.data_type, 0, 'NULL', 1, 'NUMBER', 2, 'NUMBER', 3, 'NUMBER', 4, 'NUMBER', 5, 'NUMBER', 6, 'NUMBER', 7, 'NUMBER', 8, 'NUMBER', 9, 'NUMBER', 10, 'NUMBER', 11, 'BINARY_FLOAT', 12, 'BINARY_DOUBLE', 13, 'NUMBER', 14, 'NUMBER', 15, 'NUMBER', 16, 'NUMBER', 17, 'DATE', 18, 'TIMESTAMP', 19, 'DATE', 20, 'TIME', 21, 'YEAR', 22, 'VARCHAR2', 23, 'CHAR', 24, 'HEX_STRING', 25, 'EXT', 26, 'UNKNOWN', 27, 'TINYTEXT', 28, 'TEXT', 29, 'MEDIUMTEXT', 30, decode(c.collation_type, 63, 'BLOB', 'CLOB'), 31, 'BIT', 32, 'ENUM', 33, 'SET', 34, 'ENUM_INNER', 35, 'SET_INNER', 36, concat('TIMESTAMP(', concat(c.data_scale, ') WITH TIME ZONE')), 37, concat('TIMESTAMP(', concat(c.data_scale, ') WITH LOCAL TIME ZONE')), 38, concat('TIMESTAMP(', concat(c.data_scale, ')')), 39, 'RAW', 40, concat('INTERVAL YEAR(', concat(c.data_scale, ') TO MONTH')), 41, concat('INTERVAL DAY(', concat(trunc(c.data_scale/10), concat(') TO SECOND(', concat(mod(c.data_scale, 10), ')')))), 42, 'FLOAT', 43, 'NVARCHAR2', 44, 'NCHAR', 45, '', 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, cast(c.data_length * CASE WHEN c.data_type in (22,23,30,43,44,46) and c.data_precision = 1 THEN decode(c.collation_type, 63, 1, 249, 4, 248, 4, 87, 2, 28, 2, 55, 4, 54, 4, 101, 2, 46, 4, 45, 4, 224, 4, 1) ELSE 1 END as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END END as NUMBER) as DATA_PRECISION, cast(CASE WHEN c.data_type in (11,12,17,19,22,23,27,28,29,30,42,43,44) THEN NULL ELSE CASE WHEN c.data_scale < -84 THEN NULL ELSE c.data_scale END END as NUMBER) as DATA_SCALE, cast(decode(c.nullable, 1, 'Y', 'N') as VARCHAR2(1)) as NULLABLE, cast(decode(BITAND(c.column_flags, 64), 0, c.column_id, NULL) as NUMBER) as COLUMN_ID, cast(LENGTHB(c.cur_default_value_v2) as NUMBER) as DEFAULT_LENGTH, cast(c.cur_default_value_v2 as /* TODO: LONG() */ VARCHAR(128)) as DATA_DEFAULT, cast(NULL as NUMBER) as NUM_DISTINCT, cast(NULL as /* TODO: RAW */ varchar(128)) as LOW_VALUE, cast(NULL as /* TODO: RAW */ varchar(128)) as HIGH_VALUE, cast(NULL as NUMBER) as DENSITY, cast(NULL as NUMBER) as NUM_NULLS, cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, cast(decode(c.data_type, 22, 'CHAR_CS', 23, 'CHAR_CS', 30, decode(c.collation_type, 63, 'NULL', 'CHAR_CS'), 43, 'NCHAR_CS', 44, 'NCHAR_CS', '') as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, cast(CASE WHEN c.data_type in (22,23,43,44) THEN c.data_length ELSE 0 END as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), 43, decode(c.data_precision, 1, 'C', 'B'), 44, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, cast(decode(BITAND(c.column_flags, 64), 0, 'NO', 'YES') as VARCHAR2(3)) as HIDDEN_COLUMN, cast(decode(BITAND(c.column_flags, 1), 1, 'YES', 'NO') as VARCHAR2(3)) as VIRTUAL_COLUMN, cast(NULL as NUMBER) as SEGMENT_COLUMN_ID, cast(NULL as NUMBER) as INTERNAL_COLUMN_ID, cast(NULL as VARCHAR2(15)) as HISTOGRAM, cast(c.column_name as VARCHAR2(4000)) as QUALIFIED_COL_NAME, cast('YES' as VARCHAR2(3)) as USER_GENERATED, cast(NULL as VARCHAR2(3)) as DEFAULT_ON_NULL, cast(NULL as VARCHAR2(3)) as IDENTITY_COLUMN, cast(NULL as VARCHAR2(128)) as EVALUATION_EDITION, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEFORE, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEGINNING, cast(NULL as VARCHAR2(100)) as COLLATION, cast(NULL as NUMBER) as COLLATED_COLUMN_ID FROM sys.ALL_VIRTUAL_TABLE_REAL_AGENT t JOIN sys.ALL_VIRTUAL_DATABASE_REAL_AGENT db ON db.tenant_id = t.tenant_id AND db.database_id = t.database_id AND T.TENANT_ID = EFFECTIVE_TENANT_ID() AND DB.TENANT_ID = EFFECTIVE_TENANT_ID() JOIN sys.ALL_VIRTUAL_COLUMN_REAL_AGENT c ON c.tenant_id = t.tenant_id AND c.table_id = t.table_id AND C.TENANT_ID = EFFECTIVE_TENANT_ID() WHERE c.is_hidden = 0 AND t.table_type in (0,2,3,8,9) )__"))) { LOG_ERROR("fail to set view_definition", K(ret)); } } @@ -1048,7 +1048,7 @@ int ObInnerTableSchema::user_tab_cols_v_schema(ObTableSchema &table_schema) table_schema.set_create_mem_version(1); if (OB_SUCC(ret)) { - if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT cast(t.table_name as VARCHAR2(128)) as TABLE_NAME, cast(c.column_name as VARCHAR2(128)) as COLUMN_NAME, cast(decode(c.data_type, 0, 'NULL', 1, 'NUMBER', 2, 'NUMBER', 3, 'NUMBER', 4, 'NUMBER', 5, 'NUMBER', 6, 'NUMBER', 7, 'NUMBER', 8, 'NUMBER', 9, 'NUMBER', 10, 'NUMBER', 11, 'BINARY_FLOAT', 12, 'BINARY_DOUBLE', 13, 'NUMBER', 14, 'NUMBER', 15, 'NUMBER', 16, 'NUMBER', 17, 'DATE', 18, 'TIMESTAMP', 19, 'DATE', 20, 'TIME', 21, 'YEAR', 22, 'VARCHAR2', 23, 'CHAR', 24, 'HEX_STRING', 25, 'EXT', 26, 'UNKNOWN', 27, 'TINYTEXT', 28, 'TEXT', 29, 'MEDIUMTEXT', 30, decode(c.collation_type, 63, 'BLOB', 'CLOB'), 31, 'BIT', 32, 'ENUM', 33, 'SET', 34, 'ENUM_INNER', 35, 'SET_INNER', 36, concat('TIMESTAMP(', concat(c.data_scale, ') WITH TIME ZONE')), 37, concat('TIMESTAMP(', concat(c.data_scale, ') WITH LOCAL TIME ZONE')), 38, concat('TIMESTAMP(', concat(c.data_scale, ')')), 39, 'RAW', 40, concat('INTERVAL YEAR(', concat(c.data_scale, ') TO MONTH')), 41, concat('INTERVAL DAY(', concat(trunc(c.data_scale/10), concat(') TO SECOND(', concat(mod(c.data_scale, 10), ')')))), 42, 'FLOAT', 43, 'NVARCHAR2', 44, 'NCHAR', 45, '', 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, cast(c.data_length as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END END as NUMBER) as DATA_PRECISION, cast(CASE WHEN c.data_type in (11,12,17,19,22,23,27,28,29,30,42,43,44) THEN NULL ELSE CASE WHEN c.data_scale < -84 THEN NULL ELSE c.data_scale END END as NUMBER) as DATA_SCALE, cast(decode(c.nullable, 1, 'Y', 'N') as VARCHAR2(1)) as NULLABLE, cast(decode(BITAND(c.column_flags, 64), 0, c.column_id, NULL) as NUMBER) as COLUMN_ID, cast(LENGTHB(c.cur_default_value_v2) as NUMBER) as DEFAULT_LENGTH, cast(c.cur_default_value_v2 as /* TODO: LONG() */ VARCHAR(128)) as DATA_DEFAULT, cast(NULL as NUMBER) as NUM_DISTINCT, cast(NULL as /* TODO: RAW */ varchar(128)) as LOW_VALUE, cast(NULL as /* TODO: RAW */ varchar(128)) as HIGH_VALUE, cast(NULL as NUMBER) as DENSITY, cast(NULL as NUMBER) as NUM_NULLS, cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, cast(NULL as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, cast(decode(c.data_type, 22, c.data_length, 23, c.data_length, 0) as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, cast(decode(BITAND(c.column_flags, 64), 0, 'NO', 'YES') as VARCHAR2(3)) as HIDDEN_COLUMN, cast(decode(BITAND(c.column_flags, 1), 1, 'YES', 'NO') as VARCHAR2(3)) as VIRTUAL_COLUMN, cast(NULL as NUMBER) as SEGMENT_COLUMN_ID, cast(NULL as NUMBER) as INTERNAL_COLUMN_ID, cast(NULL as VARCHAR2(15)) as HISTOGRAM, cast(c.column_name as VARCHAR2(4000)) as QUALIFIED_COL_NAME, cast('YES' as VARCHAR2(3)) as USER_GENERATED, cast(NULL as VARCHAR2(3)) as DEFAULT_ON_NULL, cast(NULL as VARCHAR2(3)) as IDENTITY_COLUMN, cast(NULL as VARCHAR2(128)) as EVALUATION_EDITION, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEFORE, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEGINNING, cast(NULL as VARCHAR2(100)) as COLLATION, cast(NULL as NUMBER) as COLLATED_COLUMN_ID FROM sys.ALL_VIRTUAL_TABLE_REAL_AGENT t JOIN sys.ALL_VIRTUAL_COLUMN_REAL_AGENT c ON c.tenant_id = t.tenant_id AND c.table_id = t.table_id AND T.TENANT_ID = EFFECTIVE_TENANT_ID() AND C.TENANT_ID = EFFECTIVE_TENANT_ID() WHERE c.is_hidden = 0 AND t.table_type in (0,2,3,8,9) AND t.database_id = USERENV('SCHEMAID') )__"))) { + if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT cast(t.table_name as VARCHAR2(128)) as TABLE_NAME, cast(c.column_name as VARCHAR2(128)) as COLUMN_NAME, cast(decode(c.data_type, 0, 'NULL', 1, 'NUMBER', 2, 'NUMBER', 3, 'NUMBER', 4, 'NUMBER', 5, 'NUMBER', 6, 'NUMBER', 7, 'NUMBER', 8, 'NUMBER', 9, 'NUMBER', 10, 'NUMBER', 11, 'BINARY_FLOAT', 12, 'BINARY_DOUBLE', 13, 'NUMBER', 14, 'NUMBER', 15, 'NUMBER', 16, 'NUMBER', 17, 'DATE', 18, 'TIMESTAMP', 19, 'DATE', 20, 'TIME', 21, 'YEAR', 22, 'VARCHAR2', 23, 'CHAR', 24, 'HEX_STRING', 25, 'EXT', 26, 'UNKNOWN', 27, 'TINYTEXT', 28, 'TEXT', 29, 'MEDIUMTEXT', 30, decode(c.collation_type, 63, 'BLOB', 'CLOB'), 31, 'BIT', 32, 'ENUM', 33, 'SET', 34, 'ENUM_INNER', 35, 'SET_INNER', 36, concat('TIMESTAMP(', concat(c.data_scale, ') WITH TIME ZONE')), 37, concat('TIMESTAMP(', concat(c.data_scale, ') WITH LOCAL TIME ZONE')), 38, concat('TIMESTAMP(', concat(c.data_scale, ')')), 39, 'RAW', 40, concat('INTERVAL YEAR(', concat(c.data_scale, ') TO MONTH')), 41, concat('INTERVAL DAY(', concat(trunc(c.data_scale/10), concat(') TO SECOND(', concat(mod(c.data_scale, 10), ')')))), 42, 'FLOAT', 43, 'NVARCHAR2', 44, 'NCHAR', 45, '', 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, cast(c.data_length * CASE WHEN c.data_type in (22,23,30,43,44,46) and c.data_precision = 1 THEN decode(c.collation_type, 63, 1, 249, 4, 248, 4, 87, 2, 28, 2, 55, 4, 54, 4, 101, 2, 46, 4, 45, 4, 224, 4, 1) ELSE 1 END as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END END as NUMBER) as DATA_PRECISION, cast(CASE WHEN c.data_type in (11,12,17,19,22,23,27,28,29,30,42,43,44) THEN NULL ELSE CASE WHEN c.data_scale < -84 THEN NULL ELSE c.data_scale END END as NUMBER) as DATA_SCALE, cast(decode(c.nullable, 1, 'Y', 'N') as VARCHAR2(1)) as NULLABLE, cast(decode(BITAND(c.column_flags, 64), 0, c.column_id, NULL) as NUMBER) as COLUMN_ID, cast(LENGTHB(c.cur_default_value_v2) as NUMBER) as DEFAULT_LENGTH, cast(c.cur_default_value_v2 as /* TODO: LONG() */ VARCHAR(128)) as DATA_DEFAULT, cast(NULL as NUMBER) as NUM_DISTINCT, cast(NULL as /* TODO: RAW */ varchar(128)) as LOW_VALUE, cast(NULL as /* TODO: RAW */ varchar(128)) as HIGH_VALUE, cast(NULL as NUMBER) as DENSITY, cast(NULL as NUMBER) as NUM_NULLS, cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, cast(decode(c.data_type, 22, 'CHAR_CS', 23, 'CHAR_CS', 30, decode(c.collation_type, 63, 'NULL', 'CHAR_CS'), 43, 'NCHAR_CS', 44, 'NCHAR_CS', '') as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, cast(CASE WHEN c.data_type in (22,23,43,44) THEN c.data_length ELSE 0 END as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), 43, decode(c.data_precision, 1, 'C', 'B'), 44, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, cast(decode(BITAND(c.column_flags, 64), 0, 'NO', 'YES') as VARCHAR2(3)) as HIDDEN_COLUMN, cast(decode(BITAND(c.column_flags, 1), 1, 'YES', 'NO') as VARCHAR2(3)) as VIRTUAL_COLUMN, cast(NULL as NUMBER) as SEGMENT_COLUMN_ID, cast(NULL as NUMBER) as INTERNAL_COLUMN_ID, cast(NULL as VARCHAR2(15)) as HISTOGRAM, cast(c.column_name as VARCHAR2(4000)) as QUALIFIED_COL_NAME, cast('YES' as VARCHAR2(3)) as USER_GENERATED, cast(NULL as VARCHAR2(3)) as DEFAULT_ON_NULL, cast(NULL as VARCHAR2(3)) as IDENTITY_COLUMN, cast(NULL as VARCHAR2(128)) as EVALUATION_EDITION, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEFORE, cast(NULL as VARCHAR2(128)) as UNUSABLE_BEGINNING, cast(NULL as VARCHAR2(100)) as COLLATION, cast(NULL as NUMBER) as COLLATED_COLUMN_ID FROM sys.ALL_VIRTUAL_TABLE_REAL_AGENT t JOIN sys.ALL_VIRTUAL_COLUMN_REAL_AGENT c ON c.tenant_id = t.tenant_id AND c.table_id = t.table_id AND T.TENANT_ID = EFFECTIVE_TENANT_ID() AND C.TENANT_ID = EFFECTIVE_TENANT_ID() WHERE c.is_hidden = 0 AND t.table_type in (0,2,3,8,9) AND t.database_id = USERENV('SCHEMAID') )__"))) { LOG_ERROR("fail to set view_definition", K(ret)); } } diff --git a/src/share/inner_table/ob_inner_table_schema_def.py b/src/share/inner_table/ob_inner_table_schema_def.py index 3812608fbe..396408edd5 100644 --- a/src/share/inner_table/ob_inner_table_schema_def.py +++ b/src/share/inner_table/ob_inner_table_schema_def.py @@ -9972,6 +9972,7 @@ def_table_schema(**gen_oracle_mapping_real_virtual_table_def('15177', True, all_ def_table_schema(**gen_oracle_mapping_real_virtual_table_def('15179', True, all_def_keywords['__all_res_mgr_consumer_group'])) + ################################################################################ # System View (20000,30000] # MySQL System View (20000, 25000] @@ -15886,7 +15887,10 @@ SELECT 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, - cast(c.data_length as NUMBER) as DATA_LENGTH, + cast(c.data_length * CASE WHEN c.data_type in (22,23,30,43,44,46) and c.data_precision = 1 + THEN decode(c.collation_type, 63, 1, 249, 4, 248, 4, 87, 2, 28, 2, 55, 4, 54, 4, 101, 2, 46, 4, 45, 4, 224, 4, 1) + ELSE 1 END + as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END @@ -15907,19 +15911,24 @@ SELECT cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, - cast(NULL as VARCHAR2(44)) as CHARACTER_SET_NAME, + cast(decode(c.data_type, + 22, 'CHAR_CS', + 23, 'CHAR_CS', + 30, decode(c.collation_type, 63, 'NULL', 'CHAR_CS'), + 43, 'NCHAR_CS', + 44, 'NCHAR_CS', + '') as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, - cast(decode(c.data_type, - 22, c.data_length, - 23, c.data_length, - 0) as NUMBER) as CHAR_LENGTH, + cast(CASE WHEN c.data_type in (22,23,43,44) THEN c.data_length ELSE 0 END as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), + 43, decode(c.data_precision, 1, 'C', 'B'), + 44, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, @@ -16031,7 +16040,10 @@ SELECT 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, - cast(c.data_length as NUMBER) as DATA_LENGTH, + cast(c.data_length * CASE WHEN c.data_type in (22,23,30,43,44,46) and c.data_precision = 1 + THEN decode(c.collation_type, 63, 1, 249, 4, 248, 4, 87, 2, 28, 2, 55, 4, 54, 4, 101, 2, 46, 4, 45, 4, 224, 4, 1) + ELSE 1 END + as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END @@ -16052,19 +16064,24 @@ SELECT cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, - cast(NULL as VARCHAR2(44)) as CHARACTER_SET_NAME, + cast(decode(c.data_type, + 22, 'CHAR_CS', + 23, 'CHAR_CS', + 30, decode(c.collation_type, 63, 'NULL', 'CHAR_CS'), + 43, 'NCHAR_CS', + 44, 'NCHAR_CS', + '') as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, - cast(decode(c.data_type, - 22, c.data_length, - 23, c.data_length, - 0) as NUMBER) as CHAR_LENGTH, + cast(CASE WHEN c.data_type in (22,23,43,44) THEN c.data_length ELSE 0 END as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), + 43, decode(c.data_precision, 1, 'C', 'B'), + 44, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, @@ -16173,7 +16190,10 @@ SELECT 'UNDEFINED') as VARCHAR2(128)) as DATA_TYPE, cast(NULL as VARCHAR2(3)) as DATA_TYPE_MOD, cast(NULL as VARCHAR2(128)) as DATA_TYPE_OWNER, - cast(c.data_length as NUMBER) as DATA_LENGTH, + cast(c.data_length * CASE WHEN c.data_type in (22,23,30,43,44,46) and c.data_precision = 1 + THEN decode(c.collation_type, 63, 1, 249, 4, 248, 4, 87, 2, 28, 2, 55, 4, 54, 4, 101, 2, 46, 4, 45, 4, 224, 4, 1) + ELSE 1 END + as NUMBER) as DATA_LENGTH, cast(CASE WHEN c.data_type in (11,12,17,18,19,22,23,27,28,29,30,36,37,38,43,44) THEN NULL ELSE CASE WHEN c.data_precision < 0 THEN NULL ELSE c.data_precision END @@ -16194,19 +16214,24 @@ SELECT cast(NULL as NUMBER) as NUM_BUCKETS, cast(NULL as DATE) as LAST_ANALYZED, cast(NULL as NUMBER) as SAMPLE_SIZE, - cast(NULL as VARCHAR2(44)) as CHARACTER_SET_NAME, + cast(decode(c.data_type, + 22, 'CHAR_CS', + 23, 'CHAR_CS', + 30, decode(c.collation_type, 63, 'NULL', 'CHAR_CS'), + 43, 'NCHAR_CS', + 44, 'NCHAR_CS', + '') as VARCHAR2(44)) as CHARACTER_SET_NAME, cast(NULL as NUMBER) as CHAR_COL_DECL_LENGTH, cast(NULL as VARCHAR2(3)) as GLOBAL_STATS, cast(NULL as VARCHAR2(3)) as USER_STATS, cast(NULL as VARCHAR2(80)) as NOTES, cast(NULL as NUMBER) as AVG_COL_LEN, - cast(decode(c.data_type, - 22, c.data_length, - 23, c.data_length, - 0) as NUMBER) as CHAR_LENGTH, + cast(CASE WHEN c.data_type in (22,23,43,44) THEN c.data_length ELSE 0 END as NUMBER) as CHAR_LENGTH, cast(decode(c.data_type, 22, decode(c.data_precision, 1, 'C', 'B'), 23, decode(c.data_precision, 1, 'C', 'B'), + 43, decode(c.data_precision, 1, 'C', 'B'), + 44, decode(c.data_precision, 1, 'C', 'B'), NULL) as VARCHAR2(1)) as CHAR_USED, cast(NULL as VARCHAR2(3)) as V80_FMT_IMAGE, cast(NULL as VARCHAR2(3)) as DATA_UPGRADED, diff --git a/src/share/object/ob_obj_cast.cpp b/src/share/object/ob_obj_cast.cpp index 8ad39d2916..298b353182 100644 --- a/src/share/object/ob_obj_cast.cpp +++ b/src/share/object/ob_obj_cast.cpp @@ -198,6 +198,8 @@ static int convert_string_collation(const ObString& in, const ObCollationType in ObCharset::charset_type_by_coll(out_collation) == CHARSET_BINARY || (ObCharset::charset_type_by_coll(in_collation) == ObCharset::charset_type_by_coll(out_collation))) { out = in; + } else if (in.empty()) { + out.reset(); } else { char* buf = NULL; const int32_t CharConvertFactorNum = 4; diff --git a/src/sql/engine/cmd/ob_load_data_impl.cpp b/src/sql/engine/cmd/ob_load_data_impl.cpp index ec7b39abc4..f7a71edff4 100644 --- a/src/sql/engine/cmd/ob_load_data_impl.cpp +++ b/src/sql/engine/cmd/ob_load_data_impl.cpp @@ -727,8 +727,11 @@ int ObLoadDataImpl::take_record_for_failed_rows(ObPhysicalPlanCtx& plan_ctx, ObL return ret; } -int ObLoadDataBase::memory_wait_local( - ObExecContext& ctx, const ObPartitionKey& part_key, ObAddr& server_addr, int64_t& total_wait_secs) +int ObLoadDataBase::memory_wait_local(ObExecContext &ctx, + const ObPartitionKey &part_key, + ObAddr &server_addr, + int64_t &total_wait_secs, + bool &is_leader_changed) { int ret = OB_SUCCESS; static const int64_t WAIT_INTERVAL_US = 1 * 1000 * 1000; // 1s @@ -811,6 +814,9 @@ int ObLoadDataBase::memory_wait_local( if (leader_addr != server_addr) { LOG_INFO("LOAD DATA location change", K(part_key), "old_addr", server_addr, "new_addr", leader_addr); server_addr = leader_addr; + is_leader_changed = true; + } else { + is_leader_changed = false; } LOG_INFO("LOAD DATA is resumed", "waited_seconds", wait_secs, K(total_wait_secs)); } @@ -3180,12 +3186,22 @@ int ObLoadDataSPImpl::handle_returned_insert_task( ObAddr& addr = part_mgr->get_leader_addr(); bool found = (OB_SUCCESS == box.server_last_available_ts.get(addr, last_ts)); if (insert_task.result_recv_ts_ > last_ts) { - if (OB_FAIL(memory_wait_local(ctx, part_mgr->get_part_key(), addr, box.wait_secs_for_mem_release))) { + bool is_leader_changed = false; + if (OB_FAIL(memory_wait_local(ctx, part_mgr->get_part_key(), + addr, box.wait_secs_for_mem_release, + is_leader_changed))) { LOG_WARN("fail to memory_wait_local", K(ret)); } else { int64_t curr_time = ObTimeUtil::current_time(); + if (is_leader_changed) { + found = (OB_SUCCESS == box.server_last_available_ts.get(addr, last_ts)); + } ret = found ? box.server_last_available_ts.update(addr, curr_time) : box.server_last_available_ts.insert(addr, curr_time); + if (OB_FAIL(ret)) { + LOG_WARN("failt to update server_last_available_ts", + K(ret), K(addr), K(found), K(is_leader_changed)); + } } } } @@ -3214,45 +3230,41 @@ int ObLoadDataSPImpl::handle_returned_insert_task( if (OB_SUCC(ret)) { switch (task_status) { - case TASK_SUCC: - box.affected_rows += insert_task.row_count_; - box.insert_rt_sum += insert_task.process_us_; - /* RESERVE FOR DEBUG - box.handle_returned_insert_task_count++; - if (insert_task.row_count_ != DEFAULT_BUFFERRED_ROW_COUNT) { - LOG_WARN("LOAD DATA task return", - "task_id", insert_task.task_id_, - "affected_rows", box.affected_rows, - "row_count", insert_task.row_count_); - } - */ - break; - case TASK_NEED_RETRY: - insert_task.retry_times_++; - need_retry = true; - LOG_WARN("LOAD DATA task need retry", - "task_id", - insert_task.task_id_, - "ret", - result.exec_ret_, - "row_count", - insert_task.row_count_); - break; - case TASK_FAILED: - if (OB_SUCCESS != log_failed_insert_task(box, insert_task)) { - LOG_WARN("fail to log failed insert task"); - } - LOG_WARN("LOAD DATA task failed", - "task_id", - insert_task.task_id_, - "ret", - result.exec_ret_, - "row_count", - insert_task.row_count_); - break; - default: - ret = OB_ERR_UNEXPECTED; - break; + case TASK_SUCC: + box.affected_rows += insert_task.row_count_; + box.insert_rt_sum += insert_task.process_us_; + /* RESERVE FOR DEBUG + box.handle_returned_insert_task_count++; + if (insert_task.row_count_ != DEFAULT_BUFFERRED_ROW_COUNT) { + LOG_WARN("LOAD DATA task return", + "task_id", insert_task.task_id_, + "affected_rows", box.affected_rows, + "row_count", insert_task.row_count_); + } + */ + break; + case TASK_NEED_RETRY: + insert_task.retry_times_++; + need_retry = true; + LOG_WARN("LOAD DATA task need retry", + "execute server", server_info->addr, + "task_id", insert_task.task_id_, + "ret", result.exec_ret_, + "row_count", insert_task.row_count_); + break; + case TASK_FAILED: + if (OB_SUCCESS != log_failed_insert_task(box, insert_task)) { + LOG_WARN("fail to log failed insert task"); + } + LOG_WARN("LOAD DATA task failed", + "execute server", server_info->addr, + "task_id", insert_task.task_id_, + "ret", result.exec_ret_, + "row_count", insert_task.row_count_); + break; + default: + ret = OB_ERR_UNEXPECTED; + break; } } @@ -3429,6 +3441,10 @@ int ObLoadDataSPImpl::insert_task_gen_and_dispatch(ObExecContext& ctx, ToolBox& LOG_WARN("fail to on task finish", K(ret)); } else if (OB_FAIL(box.insert_task_reserve_queue.push_back(insert_task))) { LOG_WARN("fail to push back", K(ret)); + } else if (OB_ISNULL(insert_task)) { + ret = OB_ERR_UNEXPECTED; + } else { + insert_task->reuse(); } } @@ -4136,11 +4152,11 @@ int ObLoadDataSPImpl::ToolBox::init(ObExecContext& ctx, ObLoadDataStmt& load_stm if (OB_SUCC(ret)) { if (OB_FAIL(shuffle_task_controller.init(parallel))) { LOG_WARN("fail to init shuffle task controller", K(ret)); - } else if (OB_FAIL(shuffle_task_reserve_queue.init(parallel))) { + } else if (OB_FAIL(shuffle_task_reserve_queue.init(parallel + 1))) { LOG_WARN("fail to init shuffle_task_reserve_queue", K(ret)); } else if (OB_FAIL(insert_task_controller.init(parallel * server_infos.count()))) { LOG_WARN("fail to init insert task controller", K(ret)); - } else if (OB_FAIL(insert_task_reserve_queue.init(parallel * server_infos.count()))) { + } else if (OB_FAIL(insert_task_reserve_queue.init(parallel * server_infos.count() + 1))) { LOG_WARN("fail to init insert_task_reserve_queue", K(ret)); } else if (OB_FAIL(ctx_allocators.reserve(parallel))) { LOG_WARN("fail to pre alloc allocators", K(ret)); diff --git a/src/sql/engine/cmd/ob_load_data_impl.h b/src/sql/engine/cmd/ob_load_data_impl.h index 5a88346624..08a868d90a 100644 --- a/src/sql/engine/cmd/ob_load_data_impl.h +++ b/src/sql/engine/cmd/ob_load_data_impl.h @@ -732,7 +732,8 @@ public: static int memory_check_remote(uint64_t tenant_id, bool& need_wait_minor_freeze); static int memory_wait_local( - ObExecContext& ctx, const ObPartitionKey& part_key, ObAddr& server_addr, int64_t& total_wait_secs); + ObExecContext& ctx, const ObPartitionKey& part_key, ObAddr& server_addr, + int64_t& total_wait_secs, bool &is_leader_changed); virtual int execute(ObExecContext& ctx, ObLoadDataStmt& load_stmt) = 0; }; diff --git a/src/sql/engine/cmd/ob_load_data_rpc.cpp b/src/sql/engine/cmd/ob_load_data_rpc.cpp index fec036b3d8..8eb5c7457d 100644 --- a/src/sql/engine/cmd/ob_load_data_rpc.cpp +++ b/src/sql/engine/cmd/ob_load_data_rpc.cpp @@ -138,11 +138,19 @@ int ObRpcLoadDataShuffleTaskExecuteP::process() LOG_WARN("LOAD DATA shuffle task timeout", K(ret), K(task)); } else if (OB_FAIL(task.shuffle_task_handle_.get_arg(handle))) { // check identifier LOG_ERROR("fail to get arg", K(ret)); - } else if (OB_FAIL(ObLoadDataSPImpl::exec_shuffle(task.task_id_, handle))) { - LOG_WARN("fail to exec shuffle task", K(ret)); + } else if (OB_ISNULL(handle)) { + ret = OB_ERR_UNEXPECTED; + LOG_ERROR("handle is null", K(ret)); + } else { + if (OB_UNLIKELY(THIS_WORKER.is_timeout())) { + ret = OB_TIMEOUT; + LOG_WARN("LOAD DATA shuffle task timeout", K(ret), K(task)); + } else if (OB_FAIL(ObLoadDataSPImpl::exec_shuffle(task.task_id_, handle))) { + LOG_WARN("fail to exec shuffle task", K(ret)); + } + handle->result.exec_ret_ = ret; } - handle->result.exec_ret_ = ret; - MEM_BARRIER(); // use handle ptr before release job ref + MEM_BARRIER(); //use handle ptr before release job ref job_status->release(); } diff --git a/src/sql/engine/cmd/ob_load_data_rpc.h b/src/sql/engine/cmd/ob_load_data_rpc.h index 7397046816..98329c0053 100644 --- a/src/sql/engine/cmd/ob_load_data_rpc.h +++ b/src/sql/engine/cmd/ob_load_data_rpc.h @@ -22,6 +22,7 @@ #include "sql/engine/cmd/ob_load_data_utils.h" #include "share/config/ob_server_config.h" #include "observer/ob_server_struct.h" +#include "lib/lock/ob_spin_lock.h" namespace oceanbase { namespace observer { @@ -279,7 +280,7 @@ public: ~ObConcurrentFixedCircularArray() { if (data_ != NULL) { - ob_free_align(static_cast(data_)); + ob_free_align((void *)(data_)); } } int init(int64_t array_size) @@ -294,8 +295,8 @@ public: } return ret; } - OB_INLINE int push_back(const T& obj) - { + OB_INLINE int push_back(const T &obj) { + common::ObSpinLockGuard guard(lock_); int ret = common::OB_SUCCESS; // push optimistically int64_t pos = ATOMIC_FAA(&head_pos_, 1); @@ -303,12 +304,13 @@ public: if (OB_UNLIKELY(pos - ATOMIC_LOAD(&tail_pos_) >= array_size_)) { ret = common::OB_SIZE_OVERFLOW; } else { - ATOMIC_SET(&data_[pos % array_size_], obj); + ATOMIC_STORE(&data_[pos % array_size_], obj); } return ret; } OB_INLINE int pop(T& output) { + common::ObSpinLockGuard guard(lock_); int ret = common::OB_SUCCESS; // pop optimistically int64_t pos = ATOMIC_FAA(&tail_pos_, 1); @@ -316,7 +318,8 @@ public: if (OB_UNLIKELY(pos >= ATOMIC_LOAD(&head_pos_))) { ret = common::OB_ARRAY_OUT_OF_RANGE; } else { - output = ATOMIC_LOAD(&data_[pos % array_size_]); + //output = ATOMIC_LOAD(&data_[pos % array_size_]); + output = ATOMIC_SET(&data_[pos % array_size_], NULL); } return ret; } @@ -328,9 +331,10 @@ public: private: // data members int64_t array_size_; - T* volatile data_; + volatile T * data_; volatile int64_t head_pos_; volatile int64_t tail_pos_; + common::ObSpinLock lock_; }; typedef ObConcurrentFixedCircularArray CompleteTaskArray; diff --git a/src/sql/engine/expr/ob_expr_eval_functions.cpp b/src/sql/engine/expr/ob_expr_eval_functions.cpp index c1ab093a70..5dcbd0cc8f 100644 --- a/src/sql/engine/expr/ob_expr_eval_functions.cpp +++ b/src/sql/engine/expr/ob_expr_eval_functions.cpp @@ -176,6 +176,8 @@ #include "ob_expr_format.h" #include "ob_expr_quarter.h" #include "ob_expr_bit_length.h" +#include "ob_expr_to_single_byte.h" +#include "ob_expr_to_multi_byte.h" namespace oceanbase { using namespace common; @@ -645,8 +647,8 @@ static ObExpr::EvalFunc g_expr_eval_functions[] = { NULL, // ObExprAsciistr::calc_asciistr_expr, /* 393 */ NULL, // ObExprAtTimeZone::eval_at_time_zone, /* 394 */ NULL, // ObExprAtLocal::eval_at_local, /* 395 */ - NULL, // ObExprToSingleByte::calc_to_single_byte, /* 396 */ - NULL, // ObExprToMultiByte::calc_to_multi_byte, /* 397 */ + ObExprToSingleByte::calc_to_single_byte, /* 396 */ + ObExprToMultiByte::calc_to_multi_byte, /* 397 */ NULL, // ObExprDllUdf::eval_dll_udf, /* 398 */ NULL, // ObExprRawtonhex::calc_rawtonhex_expr, /* 399 */ ObExprPi::eval_pi /* 400 */ diff --git a/src/sql/engine/expr/ob_expr_result_type_util.cpp b/src/sql/engine/expr/ob_expr_result_type_util.cpp index 9554f04251..b1e4892c01 100644 --- a/src/sql/engine/expr/ob_expr_result_type_util.cpp +++ b/src/sql/engine/expr/ob_expr_result_type_util.cpp @@ -613,9 +613,9 @@ int ObExprResultTypeUtil::deduce_max_string_length_oracle(const ObSQLSessionInfo if (OB_FAIL(ret)) { } else if (orig_type.is_character_type()) { - CK(LS_BYTE == orig_ls || LS_CHAR == orig_ls); - if (OB_FAIL(ret)) { - } else if (LS_BYTE == target_ls && LS_CHAR == orig_ls) { + // 当参数为 character 类型是,语义必定为 byte 或 char + if (LS_BYTE == target_ls && LS_CHAR == orig_ls) { + // 当从 char 语义 转化到 byte 语义时,需要乘以 mbmaxlen length *= mbmaxlen; } else if (LS_CHAR == target_ls && LS_BYTE == orig_ls) { ret = OB_ERR_UNEXPECTED; diff --git a/src/sql/engine/expr/ob_expr_to_multi_byte.cpp b/src/sql/engine/expr/ob_expr_to_multi_byte.cpp index 800f7fa552..e25c18095c 100644 --- a/src/sql/engine/expr/ob_expr_to_multi_byte.cpp +++ b/src/sql/engine/expr/ob_expr_to_multi_byte.cpp @@ -56,66 +56,125 @@ int ObExprToMultiByte::calc_result_type1(ObExprResType& type, ObExprResType& typ return ret; } -int ObExprToMultiByte::calc_result1(ObObj& result, const ObObj& obj, ObExprCtx& expr_ctx) const +int calc_to_multi_byte_expr(const ObString &input, const ObCollationType cs_type, + char *buf, const int64_t buf_len, int32_t &pos) +{ + int ret = OB_SUCCESS; + int64_t min_char_width = 0; + + if (OB_FAIL(ObCharset::get_mbminlen_by_coll(cs_type, min_char_width))) { + LOG_WARN("fail to get mbminlen", K(ret)); + } else if (min_char_width > 1) { + ObDataBuffer allocator(buf, buf_len); + ObString output; + + if (OB_FAIL(ob_write_string(allocator, input, output))) { + LOG_WARN("invalid input value", K(ret), K(buf_len), K(input)); + } else { + pos = output.length(); + } + } else { + ObStringScanner scanner(input, cs_type); + ObString encoding; + int32_t wc = 0; + char *ptr = buf; + + while (OB_SUCC(ret) + && scanner.next_character(encoding, wc, ret)) { + int32_t length = 0; + + if (wc == 0x20) { //处理空格 + wc = 0x3000; + //smart quote not support https://gerry.lamost.org/blog/?p=295757 + //} else if (wc == 0x22) { //" --> ” smart double quote + // wc = 0x201D; + //} else if (wc == 0x27) { //' --> ’ smart single quote + // wc = 0x2019; + } else if (wc >= 0x21 && wc <= 0x7E) { + wc += 65248; + } else { + //do nothing + } + OZ (ObCharset::wc_mb(cs_type, wc, ptr, buf + buf_len - ptr, length)); + ptr += length; + LOG_DEBUG("process char", K(ret), K(wc)); + } + pos = ptr - buf; + } + + return ret; +} + +int ObExprToMultiByte::calc_result1(ObObj &result, + const ObObj &obj, + ObExprCtx &expr_ctx) const { int ret = OB_SUCCESS; ObString src_string; - ObString dst_string; ObCollationType src_collation = obj.get_collation_type(); - int64_t min_char_width = 0; if (obj.is_null_oracle()) { result.set_null(); } else { - CK(OB_NOT_NULL(expr_ctx.calc_buf_)); - OZ(obj.get_string(src_string)); - char* buff = NULL; - int64_t buff_len = src_string.length() * 4; + CK (OB_NOT_NULL(expr_ctx.calc_buf_)); + OZ (obj.get_string(src_string)); if (OB_SUCC(ret)) { + char* buff = NULL; + int64_t buff_len = src_string.length() * ObCharset::MAX_MB_LEN; + int32_t pos = 0; + if (OB_ISNULL(buff = static_cast(expr_ctx.calc_buf_->alloc(buff_len)))) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("fail to allocate buffer", K(ret), K(buff_len)); + } else if (OB_FAIL(calc_to_multi_byte_expr(src_string, src_collation, buff, buff_len, pos))) { + LOG_WARN("fail to calc", K(ret)); } else { - dst_string.assign_buffer(buff, buff_len); + result.set_common_value(ObString(pos, buff)); + result.set_meta_type(result_type_); } } - OZ(ObCharset::get_mbminlen_by_coll(src_collation, min_char_width)); + } + return ret; +} - if (min_char_width > 1) { - OX(dst_string.write(src_string.ptr(), src_string.length())); - OX(result.set_nvarchar2(dst_string)); +int ObExprToMultiByte::cg_expr(ObExprCGCtx &op_cg_ctx, + const ObRawExpr &raw_expr, + ObExpr &rt_expr) const +{ + int ret = OB_SUCCESS; + UNUSED(op_cg_ctx); + UNUSED(raw_expr); + rt_expr.eval_func_ = calc_to_multi_byte; + return ret; +} + +int ObExprToMultiByte::calc_to_multi_byte(const ObExpr &expr, + ObEvalCtx &ctx, + ObDatum &res_datum) +{ + int ret = OB_SUCCESS; + ObDatum *src_param = NULL; + if (expr.args_[0]->eval(ctx, src_param)) { + LOG_WARN("eval arg failed", K(ret)); + } else { + if (src_param->is_null()) { + res_datum.set_null(); } else { - const char* src_ptr = src_string.ptr(); - int64_t src_pos = 0; - char* dst_ptr = buff; - int64_t dst_pos = 0; - + ObString src = src_param->get_string(); + char *buf = NULL; + int64_t buf_len = src.length() * ObCharset::MAX_MB_LEN; int32_t length = 0; - int32_t wc = 0; - while (OB_SUCC(ret) && src_pos < src_string.length()) { - OZ(ObCharset::mb_wc(src_collation, src_ptr + src_pos, src_string.length() - src_pos, length, wc)); - OX(src_pos += length); - int32_t wc_before_process = wc; - if (wc == 0x20) { - wc = 0x3000; - // smart quote not support https://gerry.lamost.org/blog/?p=295757 - //} else if (wc == 0x22) { //" --> " smart double quote - // wc = 0x201D; - //} else if (wc == 0x27) { //' --> ' smart single quote - // wc = 0x2019; - } else if (wc >= 0x21 && wc <= 0x7E) { - wc += 65248; - } else { - // do nothing - } - LOG_DEBUG("process char", K(ret), K(src_pos), K(wc_before_process), K(wc)); - OZ(ObCharset::wc_mb(src_collation, wc, dst_ptr + dst_pos, buff_len - dst_pos, length)); - OX(dst_pos += length); + + if (OB_ISNULL(buf = static_cast(expr.get_str_res_mem(ctx, buf_len)))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("fail to allocate memory", K(ret), K(src)); + } else if (OB_FAIL(calc_to_multi_byte_expr(src, expr.args_[0]->datum_meta_.cs_type_, + buf, buf_len, length))) { + LOG_WARN("fail to calc unistr", K(ret)); + } else { + res_datum.set_string(buf, length); } - OX(dst_string.assign_ptr(dst_ptr, dst_pos)); - OX(result.set_varchar(dst_string)); } - OX(result.set_collation(result_type_)); } return ret; } diff --git a/src/sql/engine/expr/ob_expr_to_multi_byte.h b/src/sql/engine/expr/ob_expr_to_multi_byte.h index 05f8b515da..5cb781f827 100644 --- a/src/sql/engine/expr/ob_expr_to_multi_byte.h +++ b/src/sql/engine/expr/ob_expr_to_multi_byte.h @@ -21,9 +21,15 @@ class ObExprToMultiByte : public ObFuncExprOperator { public: explicit ObExprToMultiByte(common::ObIAllocator& alloc); virtual ~ObExprToMultiByte(); - int calc_result_type1(ObExprResType& type, ObExprResType& type1, common::ObExprTypeCtx& type_ctx) const; - int calc_result1(common::ObObj& result, const common::ObObj& obj, common::ObExprCtx& expr_ctx) const; - + int calc_result_type1(ObExprResType &type, + ObExprResType &type1, + common::ObExprTypeCtx &type_ctx) const; + int calc_result1(common::ObObj &result, + const common::ObObj &obj, + common::ObExprCtx &expr_ctx) const; + int cg_expr(ObExprCGCtx &op_cg_ctx, const ObRawExpr &raw_expr, ObExpr &rt_expr) const; + static int calc_to_multi_byte(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum); + private: DISALLOW_COPY_AND_ASSIGN(ObExprToMultiByte); }; diff --git a/src/sql/engine/expr/ob_expr_to_single_byte.cpp b/src/sql/engine/expr/ob_expr_to_single_byte.cpp index d50bec78f9..f8fde19f82 100644 --- a/src/sql/engine/expr/ob_expr_to_single_byte.cpp +++ b/src/sql/engine/expr/ob_expr_to_single_byte.cpp @@ -48,71 +48,129 @@ int ObExprToSingleByte::calc_result_type1(ObExprResType& type, ObExprResType& ty return ret; } -int ObExprToSingleByte::calc_result1(ObObj& result, const ObObj& obj, ObExprCtx& expr_ctx) const +int calc_to_single_byte_expr(const ObString &input, const ObCollationType cs_type, + char *buf, const int64_t buf_len, int32_t &pos) { int ret = OB_SUCCESS; + int64_t min_char_width = 0; - if (obj.is_null_oracle()) { - result.set_null(); - } else { - ObString src_string; - ObString dst_string; - ObCollationType src_collation = obj.get_collation_type(); - int64_t min_char_width = 0; - char* buff = NULL; - int64_t buff_len = 0; + if (OB_FAIL(ObCharset::get_mbminlen_by_coll(cs_type, min_char_width))) { + LOG_WARN("fail to get mbminlen", K(ret)); + } else if (min_char_width > 1) { + ObDataBuffer allocator(buf, buf_len); + ObString output; - CK(OB_NOT_NULL(expr_ctx.calc_buf_)); - OZ(obj.get_string(src_string)); - if (OB_SUCC(ret)) { - buff_len = src_string.length(); - if (OB_ISNULL(buff = static_cast(expr_ctx.calc_buf_->alloc(buff_len)))) { - ret = OB_ALLOCATE_MEMORY_FAILED; - LOG_WARN("fail to allocate buffer", K(ret), K(buff_len)); - } else { - dst_string.assign_buffer(buff, buff_len); - } - } - OZ(ObCharset::get_mbminlen_by_coll(src_collation, min_char_width)); - - if (min_char_width > 1) { - OX(dst_string.write(src_string.ptr(), src_string.length())); + if (OB_FAIL(ob_write_string(allocator, input, output))) { + LOG_WARN("invalid input value", K(ret), K(buf_len), K(input)); } else { - const char* src_ptr = src_string.ptr(); - int64_t src_pos = 0; - char* dst_ptr = buff; - int64_t dst_pos = 0; - - int32_t length = 0; - int32_t wc = 0; - while (OB_SUCC(ret) && src_pos < src_string.length()) { - OZ(ObCharset::mb_wc(src_collation, src_ptr + src_pos, src_string.length() - src_pos, length, wc)); - OX(src_pos += length); - int32_t wc_before_process = wc; - if (wc == 0x3000) { - wc = 0x20; - // smart quote not support https://gerry.lamost.org/blog/?p=295757 - //} else if (wc == 0x201D) { // " --> " smart double quote - // wc = 0x22; - //} else if (wc == 0x2019) { // ' --> ' smart single quote - // wc = 0x27; - } else if (wc >= 0xFF01 && wc <= 0xFF5E) { - wc -= 65248; - } else { - // do nothing - } - OZ(ObCharset::wc_mb(src_collation, wc, dst_ptr + dst_pos, buff_len - dst_pos, length)); - OX(dst_pos += length); - LOG_DEBUG("process char", K(ret), K(src_pos), K(wc_before_process), K(wc)); - } - OX(dst_string.assign_ptr(dst_ptr, dst_pos)); + pos = output.length(); } - OX(result.set_common_value(dst_string)); - OX(result.set_meta_type(result_type_)); + } else { + ObStringScanner scanner(input, cs_type); + ObString encoding; + int32_t wc = 0; + char *ptr = buf; + + while (OB_SUCC(ret) + && scanner.next_character(encoding, wc, ret)) { + int32_t length = 0; + + if (wc == 0x3000) { //处理空格 + wc = 0x20; + //smart quote not support https://gerry.lamost.org/blog/?p=295757 + //} else if (wc == 0x201D) { // ” --> " smart double quote + // wc = 0x22; + //} else if (wc == 0x2019) { // ’ --> ' smart single quote + // wc = 0x27; + } else if (wc >= 0xFF01 && wc <= 0xFF5E) { + wc -= 65248; + } else { + //do nothing + } + OZ (ObCharset::wc_mb(cs_type, wc, ptr, buf + buf_len - ptr, length)); + ptr += length; + LOG_DEBUG("process char", K(ret), K(wc)); + } + pos = ptr - buf; } return ret; } +int ObExprToSingleByte::calc_result1(ObObj &result, + const ObObj &obj, + ObExprCtx &expr_ctx) const +{ + int ret = OB_SUCCESS; + ObString src_string; + ObCollationType src_collation = obj.get_collation_type(); + + if (obj.is_null_oracle()) { + result.set_null(); + } else { + CK (OB_NOT_NULL(expr_ctx.calc_buf_)); + OZ (obj.get_string(src_string)); + if (OB_SUCC(ret)) { + char* buff = NULL; + int64_t buff_len = src_string.length(); + int32_t pos = 0; + + if (OB_ISNULL(buff = static_cast(expr_ctx.calc_buf_->alloc(buff_len)))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("fail to allocate buffer", K(ret), K(buff_len)); + } else if (OB_FAIL(calc_to_single_byte_expr(src_string, src_collation, buff, buff_len, pos))) { + LOG_WARN("fail to calc", K(ret)); + } else { + result.set_common_value(ObString(pos, buff)); + result.set_meta_type(result_type_); + } + } + } + + return ret; +} + +int ObExprToSingleByte::cg_expr(ObExprCGCtx &op_cg_ctx, + const ObRawExpr &raw_expr, + ObExpr &rt_expr) const +{ + int ret = OB_SUCCESS; + UNUSED(op_cg_ctx); + UNUSED(raw_expr); + rt_expr.eval_func_ = calc_to_single_byte; + return ret; +} + +int ObExprToSingleByte::calc_to_single_byte(const ObExpr &expr, + ObEvalCtx &ctx, + ObDatum &res_datum) +{ + int ret = OB_SUCCESS; + ObDatum *src_param = NULL; + if (expr.args_[0]->eval(ctx, src_param)) { + LOG_WARN("eval arg failed", K(ret)); + } else { + if (src_param->is_null()) { + res_datum.set_null(); + } else { + ObString src = src_param->get_string(); + char *buf = NULL; + int64_t buf_len = src.length(); + int32_t length = 0; + + if (OB_ISNULL(buf = static_cast(expr.get_str_res_mem(ctx, buf_len)))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + LOG_WARN("fail to allocate memory", K(ret), K(src)); + } else if (OB_FAIL(calc_to_single_byte_expr(src, expr.args_[0]->datum_meta_.cs_type_, + buf, buf_len, length))) { + LOG_WARN("fail to calc unistr", K(ret)); + } else { + res_datum.set_string(buf, length); + } + } + } + return ret; +} + } // namespace sql } // namespace oceanbase diff --git a/src/sql/engine/expr/ob_expr_to_single_byte.h b/src/sql/engine/expr/ob_expr_to_single_byte.h index 9f54d36188..00e5454a0b 100644 --- a/src/sql/engine/expr/ob_expr_to_single_byte.h +++ b/src/sql/engine/expr/ob_expr_to_single_byte.h @@ -21,9 +21,14 @@ class ObExprToSingleByte : public ObFuncExprOperator { public: explicit ObExprToSingleByte(common::ObIAllocator& alloc); virtual ~ObExprToSingleByte(); - int calc_result_type1(ObExprResType& type, ObExprResType& type1, common::ObExprTypeCtx& type_ctx) const; - int calc_result1(common::ObObj& result, const common::ObObj& obj, common::ObExprCtx& expr_ctx) const; - + int calc_result_type1(ObExprResType &type, + ObExprResType &type1, + common::ObExprTypeCtx &type_ctx) const; + int calc_result1(common::ObObj &result, + const common::ObObj &obj, + common::ObExprCtx &expr_ctx) const; + int cg_expr(ObExprCGCtx &op_cg_ctx, const ObRawExpr &raw_expr, ObExpr &rt_expr) const; + static int calc_to_single_byte(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum); private: DISALLOW_COPY_AND_ASSIGN(ObExprToSingleByte); }; diff --git a/src/sql/ob_sql_utils.cpp b/src/sql/ob_sql_utils.cpp index 5d606aae27..db68723b1a 100644 --- a/src/sql/ob_sql_utils.cpp +++ b/src/sql/ob_sql_utils.cpp @@ -833,9 +833,19 @@ int ObSQLUtils::make_generated_expression_from_str(const common::ObString& expr_ int ret = OB_SUCCESS; const bool make_column_expression = false; // return ObSqlExpression ObSQLSessionInfo default_session; - if (OB_FAIL(default_session.init(0, 0, 0, &allocator))) { + uint64_t tenant_id = extract_tenant_id(schema.get_table_id()); + const ObTenantSchema *tenant_schema = nullptr; + ObSchemaGetterGuard guard; + + if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(tenant_id, guard))) { + LOG_WARN("fail to get schema guard", K(ret)); + } else if (OB_FAIL(default_session.init(0, 0, 0, &allocator))) { LOG_WARN("init empty session failed", K(ret)); - } else if (OB_FAIL(default_session.load_default_sys_variable(false, false))) { + } else if (OB_FAIL(guard.get_tenant_info(tenant_id, tenant_schema))) { + LOG_WARN("fail to get tenant_schema", K(ret)); + } else if (OB_FAIL(default_session.init_tenant(tenant_schema->get_tenant_name_str(), tenant_id))) { + LOG_WARN("fail to init", K(ret)); + } else if (OB_FAIL(default_session.load_all_sys_vars(guard))) { LOG_WARN("session load default system variable failed", K(ret)); } else if (OB_FAIL(make_generated_expression_from_str( expr_str, default_session, schema, gen_col, col_ids, allocator, expression, make_column_expression))) { @@ -938,19 +948,26 @@ int ObSQLUtils::make_generated_expression_from_str(const common::ObString& expr_ return ret; } -int ObSQLUtils::make_default_expr_context(ObIAllocator& allocator, ObExprCtx& expr_ctx) +int ObSQLUtils::make_default_expr_context(uint64_t tenant_id, ObIAllocator &allocator, ObExprCtx &expr_ctx) { int ret = OB_SUCCESS; - - ObSQLSessionInfo* default_session = static_cast(allocator.alloc(sizeof(ObSQLSessionInfo))); + ObSchemaGetterGuard guard; + const ObTenantSchema *tenant_schema = nullptr; + ObSQLSessionInfo *default_session = static_cast(allocator.alloc(sizeof(ObSQLSessionInfo))); if (OB_ISNULL(default_session)) { ret = OB_ALLOCATE_MEMORY_FAILED; LOG_WARN("allocate memory failed", K(ret)); + } else if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(tenant_id, guard))) { + LOG_WARN("fail to get schema guard", K(ret)); } else { default_session = new (default_session) ObSQLSessionInfo(); if (OB_FAIL(default_session->init(0, 0, 0, &allocator))) { LOG_WARN("init default session failed", K(ret)); - } else if (OB_FAIL(default_session->load_default_sys_variable(false, false))) { + } else if (OB_FAIL(guard.get_tenant_info(tenant_id, tenant_schema))) { + LOG_WARN("fail to get tenant_schema", K(ret)); + } else if (OB_FAIL(default_session->init_tenant(tenant_schema->get_tenant_name_str(), tenant_id))) { + LOG_WARN("fail to init", K(ret)); + } else if (OB_FAIL(default_session->load_all_sys_vars(guard))) { LOG_WARN("load default system variable to session failed", K(ret)); } else { expr_ctx.my_session_ = default_session; @@ -1025,6 +1042,9 @@ int ObSQLUtils::calc_sql_expression(const ObISqlExpression* expr, const share::s const ObIArray& col_ids, const ObNewRow& row, ObIAllocator& allocator, ObExprCtx& expr_ctx, ObObj& result) { + UNUSED(schema); + UNUSED(allocator); + UNUSED(col_ids); int ret = OB_SUCCESS; if (OB_ISNULL(expr)) { ret = OB_INVALID_ARGUMENT; @@ -1035,6 +1055,7 @@ int ObSQLUtils::calc_sql_expression(const ObISqlExpression* expr, const share::s } else { ObNewRow pad_row; bool need_pad = false; + /* if (is_pad_char_to_full_length(expr_ctx.my_session_->get_sql_mode())) { ObSEArray whitespace_length; for (int64_t i = 0; OB_SUCC(ret) && i < col_ids.count(); ++i) { @@ -1092,10 +1113,11 @@ int ObSQLUtils::calc_sql_expression(const ObISqlExpression* expr, const share::s } } } + */ if (OB_SUCC(ret)) { if (OB_FAIL(expr->calc(expr_ctx, need_pad ? pad_row : row, result))) { - LOG_WARN("Fail to calc value", K(*expr), K(row), K(ret)); + LOG_WARN("Fail to calc value", K(ret), K(*expr), K(row), K(need_pad), K(pad_row)); } } } diff --git a/src/sql/ob_sql_utils.h b/src/sql/ob_sql_utils.h index 413670e128..2da8968a74 100644 --- a/src/sql/ob_sql_utils.h +++ b/src/sql/ob_sql_utils.h @@ -169,7 +169,7 @@ public: const share::schema::ObTableSchema& schema, const share::schema::ObColumnSchemaV2& gen_col, const common::ObIArray& col_ids, common::ObIAllocator& allocator, common::ObISqlExpression*& expression, const bool make_column_expression); - static int make_default_expr_context(ObIAllocator& allocator, ObExprCtx& expr_ctx); + static int make_default_expr_context(uint64_t tenant_id, ObIAllocator& allocator, ObExprCtx& expr_ctx); static int calc_sql_expression(const ObISqlExpression* expr, const share::schema::ObTableSchema& schema, const ObIArray& col_ids, const ObNewRow& row, ObIAllocator& allocator, ObExprCtx& expr_ctx, ObObj& result); diff --git a/src/sql/resolver/expr/ob_raw_expr_deduce_type.cpp b/src/sql/resolver/expr/ob_raw_expr_deduce_type.cpp index 51d96d676a..82ea336c8e 100644 --- a/src/sql/resolver/expr/ob_raw_expr_deduce_type.cpp +++ b/src/sql/resolver/expr/ob_raw_expr_deduce_type.cpp @@ -373,7 +373,10 @@ int ObRawExprDeduceType::calc_result_type( LOG_DEBUG("debug for expr params calc meta", K(types)); - if (OB_SUCC(ret) && share::is_oracle_mode() && !my_session_->use_static_typing_engine()) { + if (OB_SUCC(ret) + && share::is_oracle_mode() + && expr.get_expr_type() != T_FUN_SYS_NVL + && !my_session_->use_static_typing_engine()) { for (int64_t i = 0; OB_SUCC(ret) && i < types.count(); i++) { ObExprResType& param = types.at(i); if (param.get_calc_meta().is_character_type()) { diff --git a/src/sql/session/ob_basic_session_info.h b/src/sql/session/ob_basic_session_info.h index 59305ee121..ae02637eaa 100644 --- a/src/sql/session/ob_basic_session_info.h +++ b/src/sql/session/ob_basic_session_info.h @@ -2282,7 +2282,8 @@ inline ObLengthSemantics ObBasicSessionInfo::get_local_nls_length_semantics() co // oracle SYS user actual nls_length_semantics is always BYTE inline ObLengthSemantics ObBasicSessionInfo::get_actual_nls_length_semantics() const { - return (is_oracle_sys_user() ? LS_BYTE : sys_vars_cache_.get_nls_length_semantics()); + return OB_ORA_SYS_DATABASE_ID == extract_pure_id(get_database_id()) ? + LS_BYTE : sys_vars_cache_.get_nls_length_semantics(); } inline int64_t ObBasicSessionInfo::get_local_ob_org_cluster_id() const diff --git a/src/storage/compaction/ob_partition_merge.cpp b/src/storage/compaction/ob_partition_merge.cpp index a2ba5e51cc..8e74b7e55a 100644 --- a/src/storage/compaction/ob_partition_merge.cpp +++ b/src/storage/compaction/ob_partition_merge.cpp @@ -417,7 +417,8 @@ int ObMajorPartitionMergeFuser::inner_init(const ObMergeParameter& merge_param) } } if (OB_SUCC(ret) && has_generated_column) { - if (OB_FAIL(sql::ObSQLUtils::make_default_expr_context(allocator_, expr_ctx_))) { + uint64_t tenant_id = extract_tenant_id(merge_param.table_schema_->get_table_id()); + if (OB_FAIL(sql::ObSQLUtils::make_default_expr_context(tenant_id, allocator_, expr_ctx_))) { STORAGE_LOG(WARN, "Failed to make default expr context ", K(ret)); } } diff --git a/src/storage/ob_partition_storage.cpp b/src/storage/ob_partition_storage.cpp index 29672d2368..c17890c65e 100644 --- a/src/storage/ob_partition_storage.cpp +++ b/src/storage/ob_partition_storage.cpp @@ -5526,7 +5526,8 @@ int ObPartitionStorage::local_sort_index_by_range( // extend col_ids for generated column ObArray extended_col_ids; ObArray org_extended_col_ids; - ObArray dependent_exprs; + ObArray dependent_exprs; + ObArray gen_col_schemas; ObExprCtx expr_ctx; if (OB_SUCC(ret)) { ObArray index_table_columns; @@ -5618,12 +5619,15 @@ int ObPartitionStorage::local_sort_index_by_range( K(ret)); } else if (OB_FAIL(dependent_exprs.push_back(expr))) { STORAGE_LOG(WARN, "push back error", K(ret)); - } else { /*do nothing*/ + } else if (OB_FAIL(gen_col_schemas.push_back(column_schema))) { + STORAGE_LOG(WARN, "push back error", K(ret)); } } } else { if (OB_FAIL(dependent_exprs.push_back(NULL))) { STORAGE_LOG(WARN, "push back error", K(ret)); + } else if (OB_FAIL(gen_col_schemas.push_back(NULL))) { + STORAGE_LOG(WARN, "push back error", K(ret)); } } } @@ -5751,7 +5755,8 @@ int ObPartitionStorage::local_sort_index_by_range( int64_t t2 = 0; int64_t t3 = 0; int64_t t4 = 0; - if (OB_FAIL(sql::ObSQLUtils::make_default_expr_context(allocator, expr_ctx))) { + uint64_t tenant_id = extract_tenant_id(table_schema->get_table_id()); + if (OB_FAIL(sql::ObSQLUtils::make_default_expr_context(tenant_id, allocator, expr_ctx))) { STORAGE_LOG(WARN, "failed to make default expr context ", K(ret)); } tables_handle.reset(); @@ -5784,8 +5789,16 @@ int ObPartitionStorage::local_sort_index_by_range( calc_buf, expr_ctx, tmp_row.row_val_.cells_[k]))) { - STORAGE_LOG( - WARN, "failed to calc expr", K(row->row_val_), K(org_col_ids), K(dependent_exprs.at(k)), K(ret)); + STORAGE_LOG(WARN, "failed to calc expr", K(row->row_val_), K(org_col_ids), + K(dependent_exprs.at(k)), K(ret)); + } else if (OB_UNLIKELY(!tmp_row.row_val_.cells_[k].is_null() + && !sql::ObSQLUtils::is_same_type_for_compare( + gen_col_schemas.at(k)->get_meta_type(), + tmp_row.row_val_.cells_[k].get_meta()))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("result type is not consistent with schema, please check expr result", + K(ret), "column schema type", gen_col_schemas.at(k)->get_meta_type(), + "result", tmp_row.row_val_.cells_[k]); } } else { tmp_row.row_val_.cells_[k] = default_row.row_val_.cells_[k];