fix some optimizer stats and regexp bugs
This commit is contained in:
		@ -3580,7 +3580,7 @@ int ObDbmsStats::parse_table_info(ObExecContext &ctx,
 | 
				
			|||||||
      } else {/*do nothing*/}
 | 
					      } 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.table_id_ = table_schema->get_table_id();
 | 
				
			||||||
    param.part_level_ = table_schema->get_part_level();
 | 
					    param.part_level_ = table_schema->get_part_level();
 | 
				
			||||||
    if (OB_FAIL(set_param_global_part_id(ctx, param))) {
 | 
					    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.tenant_id_ = session->get_effective_tenant_id();
 | 
				
			||||||
    param.is_temp_table_ = table_schema->is_tmp_table();
 | 
					    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.table_id_ = table_schema->get_table_id();
 | 
				
			||||||
    param.part_level_ = table_schema->get_part_level();
 | 
					    param.part_level_ = table_schema->get_part_level();
 | 
				
			||||||
    if (OB_FAIL(set_param_global_part_id(ctx, param))) {
 | 
					    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;
 | 
					            ret = OB_ERR_UNEXPECTED;
 | 
				
			||||||
            LOG_WARN("get unexpected null", K(ret));
 | 
					            LOG_WARN("get unexpected null", K(ret));
 | 
				
			||||||
          } else if (!(table_schemas.at(i)->is_user_table() ||
 | 
					          } 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:
 | 
					            // only need following tables:
 | 
				
			||||||
            // 1. user table
 | 
					            // 1. user table
 | 
				
			||||||
            // 2. valid sys table and real agent virtual 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;
 | 
					            ret = OB_ERR_UNEXPECTED;
 | 
				
			||||||
            LOG_WARN("get unexpected null", K(ret), K(table_schema));
 | 
					            LOG_WARN("get unexpected null", K(ret), K(table_schema));
 | 
				
			||||||
          } else if (!(table_schema->is_user_table() ||
 | 
					          } 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:
 | 
					            // only gather statistics for following tables:
 | 
				
			||||||
            // 1. user table
 | 
					            // 1. user table
 | 
				
			||||||
            // 2. valid sys table and real agent virtual table
 | 
					            // 2. valid sys table and real agent virtual table
 | 
				
			||||||
 | 
				
			|||||||
@ -186,10 +186,13 @@ int ObDbmsStatsUtils::check_table_read_write_valid(const uint64_t tenant_id, boo
 | 
				
			|||||||
  return ret;
 | 
					  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;
 | 
					  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) ||
 | 
					         !(is_core_table(table_id) ||
 | 
				
			||||||
           ObSysTableChecker::is_sys_table_index_tid(table_id) ||
 | 
					           ObSysTableChecker::is_sys_table_index_tid(table_id) ||
 | 
				
			||||||
           id == share::OB_ALL_TABLE_STAT_TID ||
 | 
					           id == share::OB_ALL_TABLE_STAT_TID ||
 | 
				
			||||||
 | 
				
			|||||||
@ -61,7 +61,7 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  static int check_table_read_write_valid(const uint64_t tenant_id, bool &is_valid);
 | 
					  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,
 | 
					  static int parse_granularity(const ObString &granularity,
 | 
				
			||||||
                               bool &need_global,
 | 
					                               bool &need_global,
 | 
				
			||||||
 | 
				
			|||||||
@ -14,6 +14,7 @@
 | 
				
			|||||||
#include "ob_stats_estimator.h"
 | 
					#include "ob_stats_estimator.h"
 | 
				
			||||||
#include "share/stat/ob_dbms_stats_utils.h"
 | 
					#include "share/stat/ob_dbms_stats_utils.h"
 | 
				
			||||||
#include "observer/ob_inner_sql_connection_pool.h"
 | 
					#include "observer/ob_inner_sql_connection_pool.h"
 | 
				
			||||||
 | 
					#include "sql/optimizer/ob_opt_selectivity.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace oceanbase
 | 
					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_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_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());
 | 
					        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));
 | 
					          LOG_WARN("failed to copy col stat", K(ret));
 | 
				
			||||||
        } else {/*do nothing*/}
 | 
					        } else {/*do nothing*/}
 | 
				
			||||||
      } else {/*do nothing*/}
 | 
					      } else {/*do nothing*/}
 | 
				
			||||||
@ -463,7 +464,9 @@ int ObStatsEstimator::copy_opt_stat(ObOptStat &src_opt_stat,
 | 
				
			|||||||
  return ret;
 | 
					  return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ObStatsEstimator::copy_col_stats(ObIArray<ObOptColumnStat *> &src_col_stats,
 | 
					int ObStatsEstimator::copy_col_stats(const int64_t cur_row_cnt,
 | 
				
			||||||
 | 
					                                     const int64_t total_row_cnt,
 | 
				
			||||||
 | 
					                                     ObIArray<ObOptColumnStat *> &src_col_stats,
 | 
				
			||||||
                                     ObIArray<ObOptColumnStat *> &dst_col_stats)
 | 
					                                     ObIArray<ObOptColumnStat *> &dst_col_stats)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  int ret = OB_SUCCESS;
 | 
					  int ret = OB_SUCCESS;
 | 
				
			||||||
@ -480,9 +483,9 @@ int ObStatsEstimator::copy_col_stats(ObIArray<ObOptColumnStat *> &src_col_stats,
 | 
				
			|||||||
        int64_t num_null = src_col_stats.at(i)->get_num_null();
 | 
					        int64_t num_null = src_col_stats.at(i)->get_num_null();
 | 
				
			||||||
        int64_t num_distinct = src_col_stats.at(i)->get_num_distinct();
 | 
					        int64_t num_distinct = src_col_stats.at(i)->get_num_distinct();
 | 
				
			||||||
        if (sample_value_ >= 0.000001 && sample_value_ < 100.0) {
 | 
					        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<int64_t>(num_not_null * 100 / sample_value_);
 | 
					          num_not_null = static_cast<int64_t>(num_not_null * 100 / sample_value_);
 | 
				
			||||||
          num_null = static_cast<int64_t>(num_null * 100 / sample_value_);
 | 
					          num_null = static_cast<int64_t>(num_null * 100 / sample_value_);
 | 
				
			||||||
          num_distinct = static_cast<int64_t>(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_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());
 | 
					        dst_col_stats.at(i)->set_min_value(src_col_stats.at(i)->get_min_value());
 | 
				
			||||||
 | 
				
			|||||||
@ -100,7 +100,9 @@ private:
 | 
				
			|||||||
  int copy_hybrid_hist_stat(ObOptStat &src_opt_stat,
 | 
					  int copy_hybrid_hist_stat(ObOptStat &src_opt_stat,
 | 
				
			||||||
                            ObIArray<ObOptStat> &dst_opt_stats);
 | 
					                            ObIArray<ObOptStat> &dst_opt_stats);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  int copy_col_stats(ObIArray<ObOptColumnStat *> &src_col_stats,
 | 
					  int copy_col_stats(const int64_t cur_row_cnt,
 | 
				
			||||||
 | 
					                     const int64_t total_row_cnt,
 | 
				
			||||||
 | 
					                     ObIArray<ObOptColumnStat *> &src_col_stats,
 | 
				
			||||||
                     ObIArray<ObOptColumnStat *> &dst_col_stats);
 | 
					                     ObIArray<ObOptColumnStat *> &dst_col_stats);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
protected:
 | 
					protected:
 | 
				
			||||||
 | 
				
			|||||||
@ -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.
 | 
					    //oracle mode replace string '\1' <==> '$1' in mysql mode, we need extra convert.
 | 
				
			||||||
    UErrorCode m_error_code = U_ZERO_ERROR;
 | 
					    UErrorCode m_error_code = U_ZERO_ERROR;
 | 
				
			||||||
    int32_t group_count = uregex_groupCount(regexp_engine_, &m_error_code);
 | 
					    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))) {
 | 
					    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)));
 | 
					      LOG_WARN("failed to check icu regexp status", K(ret), K(u_errorName(m_error_code)));
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user