From b2bb787f93ec433d2f2669eee6aba7935d9407e3 Mon Sep 17 00:00:00 2001 From: qichang Date: Tue, 25 Feb 2025 16:56:42 +0800 Subject: [PATCH] Revert "handle empty cbo stats" This reverts commit 64695733050e3a7303222b8d73c9497064456427. --- storage/ctc/ha_ctc.cc | 48 +-------------------------------------- storage/ctc/ha_ctc.h | 3 --- storage/ctc/ha_ctcpart.cc | 37 ++++++++++++------------------ 3 files changed, 15 insertions(+), 73 deletions(-) diff --git a/storage/ctc/ha_ctc.cc b/storage/ctc/ha_ctc.cc index dd89fe6..178c2ae 100644 --- a/storage/ctc/ha_ctc.cc +++ b/storage/ctc/ha_ctc.cc @@ -3369,45 +3369,6 @@ EXTER_ATTACK int ha_ctc::rnd_pos(uchar *buf, uchar *pos) { return ret; } -/* -The given SQL command may require the use of statistics information. -*/ -bool requires_stats_info(enum_sql_command sql_command) { - switch (sql_command) { - case SQLCOM_DELETE: - case SQLCOM_SELECT: - case SQLCOM_UPDATE: - case SQLCOM_DELETE_MULTI: - case SQLCOM_UPDATE_MULTI: - return true; - default: - return false; - } -} - -/* -Handle the statistics are empty case, -prevent full-table scan by query_sql with where_cond -*/ -ct_errno_t ha_ctc::handle_cbo_stats_empty(THD* thd) { - ct_errno_t ret = CT_SUCCESS; - if (stats.records == 0 && requires_stats_info(thd->lex->sql_command) && - thd->lex->query_block->where_cond() != nullptr) { - std::lock_guard lock(analyze_mutex); - if (stats.records == 0) { - ret = (ct_errno_t)analyze(thd, nullptr); - if (ret != CT_SUCCESS) { - ctc_log_error("sql %s execute analyze failed!", thd->query().str); - return ret; - } - ctc_log_system("sql %s handle empty cbo statistics.", thd->query().str); - ret = (ct_errno_t)get_cbo_stats_4share(); - info_low(); - } - } - return ret; -} - /** @brief ::info() is used to return information to the optimizer. See my_base.h for @@ -3485,16 +3446,9 @@ int ha_ctc::info(uint flag) { END_RECORD_STATS(EVENT_TYPE_GET_CBO) return convert_ctc_error_code_to_mysql(ret); } - - info_low(); - - ret = handle_cbo_stats_empty(thd); - if (ret != CT_SUCCESS) { - END_RECORD_STATS(EVENT_TYPE_GET_CBO) - return convert_ctc_error_code_to_mysql(ret); - } } + info_low(); if (stats.records < 2) { /* This is a lie, but you don't want the optimizer to see zero or 1 */ stats.records = 3; diff --git a/storage/ctc/ha_ctc.h b/storage/ctc/ha_ctc.h index 467677a..44399d5 100644 --- a/storage/ctc/ha_ctc.h +++ b/storage/ctc/ha_ctc.h @@ -956,9 +956,6 @@ public: virtual void free_cbo_stats(); virtual int get_cbo_stats_4share(); - - std::mutex analyze_mutex; - virtual ct_errno_t handle_cbo_stats_empty(THD* thd); bool m_ror_intersect = false; diff --git a/storage/ctc/ha_ctcpart.cc b/storage/ctc/ha_ctcpart.cc index 6279946..0db2188 100644 --- a/storage/ctc/ha_ctcpart.cc +++ b/storage/ctc/ha_ctcpart.cc @@ -961,36 +961,27 @@ int ha_ctcpart::analyze(THD *thd, HA_CHECK_OPT *opt) { return 0; } Alter_info *const alter_info = get_thd()->lex->alter_info; + if ((alter_info->flags & Alter_info::ALTER_ADMIN_PARTITION) == 0 || + (alter_info->flags & Alter_info::ALTER_ALL_PARTITION)) { + m_tch.part_id = INVALID_PART_ID; + m_part_share->need_fetch_cbo = true; + return ha_ctc::analyze(thd, opt); + } int ret; uint32_t used_parts; uint32_t *part_ids = nullptr; uint32_t *subpart_ids = nullptr; - if (alter_info != nullptr) { - if ((alter_info->flags & Alter_info::ALTER_ADMIN_PARTITION) == 0 || - (alter_info->flags & Alter_info::ALTER_ALL_PARTITION)) { - m_tch.part_id = INVALID_PART_ID; - m_part_share->need_fetch_cbo = true; - return ha_ctc::analyze(thd, opt); - } - bool memory_allocated = false; - if (!m_part_info->set_read_partitions(&alter_info->partition_names)) { - memory_allocated = get_used_partitions(m_part_info, &part_ids, &subpart_ids, &used_parts); - if(!memory_allocated){ - ctc_log_error("Failed to allocate memory !"); - return HA_ERR_OUT_OF_MEM; - } - } else { - ctc_log_error("no partition alter !"); - return HA_ERR_GENERIC; + bool memory_allocated = false; + if (!m_part_info->set_read_partitions(&alter_info->partition_names)) { + memory_allocated = get_used_partitions(m_part_info, &part_ids, &subpart_ids, &used_parts); + if(!memory_allocated){ + ctc_log_error("Failed to allocate memory !"); + return HA_ERR_OUT_OF_MEM; } } else { - my_free(part_ids); - my_free(subpart_ids); - m_tch.part_id = INVALID_PART_ID; - m_part_share->need_fetch_cbo = true; - return ha_ctc::analyze(thd, opt); + ctc_log_error("no partition alter !"); + return HA_ERR_GENERIC; } - if (m_part_info->num_parts == used_parts) { m_tch.part_id = INVALID_PART_ID; my_free(part_ids); -- Gitee