diff --git a/src/pl/sys_package/ob_dbms_stats.cpp b/src/pl/sys_package/ob_dbms_stats.cpp index 2553eadf25..72617a8ebc 100644 --- a/src/pl/sys_package/ob_dbms_stats.cpp +++ b/src/pl/sys_package/ob_dbms_stats.cpp @@ -3580,7 +3580,7 @@ int ObDbmsStats::parse_table_info(ObExecContext &ctx, } else {/*do nothing*/} } } - if (OB_SUCC(ret) && table_schema != NULL) { + if (OB_SUCC(ret) && table_schema != NULL && !table_schema->is_view_table()) { param.table_id_ = table_schema->get_table_id(); param.part_level_ = table_schema->get_part_level(); if (OB_FAIL(set_param_global_part_id(ctx, param))) { @@ -3629,7 +3629,7 @@ int ObDbmsStats::parse_table_info(ObExecContext &ctx, param.tenant_id_ = session->get_effective_tenant_id(); param.is_temp_table_ = table_schema->is_tmp_table(); } - if (OB_SUCC(ret) && table_schema != NULL) { + if (OB_SUCC(ret) && table_schema != NULL && !table_schema->is_view_table()) { param.table_id_ = table_schema->get_table_id(); param.part_level_ = table_schema->get_part_level(); if (OB_FAIL(set_param_global_part_id(ctx, param))) { @@ -5094,7 +5094,8 @@ int ObDbmsStats::get_all_table_ids_in_database(ObExecContext &ctx, ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret)); } else if (!(table_schemas.at(i)->is_user_table() || - ObDbmsStatsUtils::is_stat_sys_table(table_schemas.at(i)->get_table_id()))) { + ObDbmsStatsUtils::is_stat_sys_table(stat_param.tenant_id_, + table_schemas.at(i)->get_table_id()))) { // only need following tables: // 1. user table // 2. valid sys table and real agent virtual table @@ -5215,7 +5216,8 @@ int ObDbmsStats::get_need_statistics_tables(sql::ObExecContext &ctx, ret = OB_ERR_UNEXPECTED; LOG_WARN("get unexpected null", K(ret), K(table_schema)); } else if (!(table_schema->is_user_table() || - ObDbmsStatsUtils::is_stat_sys_table(table_schema->get_table_id()))) { + ObDbmsStatsUtils::is_stat_sys_table(tenant_id, + table_schema->get_table_id()))) { // only gather statistics for following tables: // 1. user table // 2. valid sys table and real agent virtual table diff --git a/src/share/stat/ob_dbms_stats_utils.cpp b/src/share/stat/ob_dbms_stats_utils.cpp index cd315fbdd7..7cd4c88474 100644 --- a/src/share/stat/ob_dbms_stats_utils.cpp +++ b/src/share/stat/ob_dbms_stats_utils.cpp @@ -186,10 +186,13 @@ int ObDbmsStatsUtils::check_table_read_write_valid(const uint64_t tenant_id, boo return ret; } -bool ObDbmsStatsUtils::is_stat_sys_table(const int64_t table_id) +bool ObDbmsStatsUtils::is_stat_sys_table(const uint64_t tenant_id, const int64_t table_id) { const uint64_t id = table_id; - return (is_sys_table(id) || share::is_oracle_mapping_real_virtual_table(id)) && + return (is_sys_table(id) || + (share::is_oracle_mapping_real_virtual_table(id) && + (!is_restrict_access_virtual_table(id) || tenant_id == OB_SYS_TENANT_ID)) + ) && !(is_core_table(table_id) || ObSysTableChecker::is_sys_table_index_tid(table_id) || id == share::OB_ALL_TABLE_STAT_TID || diff --git a/src/share/stat/ob_dbms_stats_utils.h b/src/share/stat/ob_dbms_stats_utils.h index ef7c920369..d0cb3d6a36 100644 --- a/src/share/stat/ob_dbms_stats_utils.h +++ b/src/share/stat/ob_dbms_stats_utils.h @@ -61,7 +61,7 @@ public: static int check_table_read_write_valid(const uint64_t tenant_id, bool &is_valid); - static bool is_stat_sys_table(const int64_t table_id); + static bool is_stat_sys_table(const uint64_t tenant_id, const int64_t table_id); static int parse_granularity(const ObString &granularity, bool &need_global, diff --git a/src/share/stat/ob_stats_estimator.cpp b/src/share/stat/ob_stats_estimator.cpp index d4c133c933..0c37f98f9f 100644 --- a/src/share/stat/ob_stats_estimator.cpp +++ b/src/share/stat/ob_stats_estimator.cpp @@ -14,6 +14,7 @@ #include "ob_stats_estimator.h" #include "share/stat/ob_dbms_stats_utils.h" #include "observer/ob_inner_sql_connection_pool.h" +#include "sql/optimizer/ob_opt_selectivity.h" namespace oceanbase { @@ -450,7 +451,7 @@ int ObStatsEstimator::copy_opt_stat(ObOptStat &src_opt_stat, dst_opt_stats.at(i).table_stat_->set_row_count(row_cnt); dst_opt_stats.at(i).table_stat_->set_avg_row_size(tmp_tab_stat->get_avg_row_size()); dst_opt_stats.at(i).table_stat_->set_sample_size(tmp_tab_stat->get_row_count()); - if (OB_FAIL(copy_col_stats(tmp_col_stats, dst_opt_stats.at(i).column_stats_))) { + if (OB_FAIL(copy_col_stats(tmp_tab_stat->get_row_count(), row_cnt, tmp_col_stats, dst_opt_stats.at(i).column_stats_))) { LOG_WARN("failed to copy col stat", K(ret)); } else {/*do nothing*/} } else {/*do nothing*/} @@ -463,7 +464,9 @@ int ObStatsEstimator::copy_opt_stat(ObOptStat &src_opt_stat, return ret; } -int ObStatsEstimator::copy_col_stats(ObIArray &src_col_stats, +int ObStatsEstimator::copy_col_stats(const int64_t cur_row_cnt, + const int64_t total_row_cnt, + ObIArray &src_col_stats, ObIArray &dst_col_stats) { int ret = OB_SUCCESS; @@ -480,9 +483,9 @@ int ObStatsEstimator::copy_col_stats(ObIArray &src_col_stats, int64_t num_null = src_col_stats.at(i)->get_num_null(); int64_t num_distinct = src_col_stats.at(i)->get_num_distinct(); if (sample_value_ >= 0.000001 && sample_value_ < 100.0) { + num_distinct = ObOptSelectivity::scale_distinct(total_row_cnt, cur_row_cnt, num_distinct); num_not_null = static_cast(num_not_null * 100 / sample_value_); num_null = static_cast(num_null * 100 / sample_value_); - num_distinct = static_cast(num_distinct * 100 / sample_value_); } dst_col_stats.at(i)->set_max_value(src_col_stats.at(i)->get_max_value()); dst_col_stats.at(i)->set_min_value(src_col_stats.at(i)->get_min_value()); diff --git a/src/share/stat/ob_stats_estimator.h b/src/share/stat/ob_stats_estimator.h index 97dca2b87f..b4ea407a77 100644 --- a/src/share/stat/ob_stats_estimator.h +++ b/src/share/stat/ob_stats_estimator.h @@ -100,7 +100,9 @@ private: int copy_hybrid_hist_stat(ObOptStat &src_opt_stat, ObIArray &dst_opt_stats); - int copy_col_stats(ObIArray &src_col_stats, + int copy_col_stats(const int64_t cur_row_cnt, + const int64_t total_row_cnt, + ObIArray &src_col_stats, ObIArray &dst_col_stats); protected: diff --git a/src/sql/engine/expr/ob_expr_regexp_context.cpp b/src/sql/engine/expr/ob_expr_regexp_context.cpp index abf07e0355..ae4e69803c 100644 --- a/src/sql/engine/expr/ob_expr_regexp_context.cpp +++ b/src/sql/engine/expr/ob_expr_regexp_context.cpp @@ -782,7 +782,7 @@ int ObExprRegexContext::get_valid_replace_string(ObIAllocator &alloc, //oracle mode replace string '\1' <==> '$1' in mysql mode, we need extra convert. UErrorCode m_error_code = U_ZERO_ERROR; int32_t group_count = uregex_groupCount(regexp_engine_, &m_error_code); - MEMSET(u_replace, 0, origin_replace.length() * sizeof(UChar)); + MEMSET(u_replace, 0, buf_len); if (OB_FAIL(check_icu_regexp_status(m_error_code))) { LOG_WARN("failed to check icu regexp status", K(ret), K(u_errorName(m_error_code))); } else {