diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 703d903a01b89245b541d067128db1c79ee35be8..3b26b16010baadade2ea2dd8850b599330950496 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -5309,10 +5309,45 @@ void ha_tse::free_cbo_stats() */ const Item *ha_tse::cond_push(const Item *cond, bool other_tbls_ok MY_ATTRIBUTE((unused))) { + assert(m_cond == nullptr); assert(pushed_cond == nullptr); assert(cond != nullptr); - const Item *remainder; - remainder = cond; + const Item *remainder = cond; + + THD *const thd = table->in_use; + if (!thd->optimizer_switch_flag(OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN)) { + return remainder; + } + if (thd->lex->all_query_blocks_list && thd->lex->all_query_blocks_list->is_recursive()) { + return remainder; + } + + prep_cond_push(cond); + if (m_pushed_conds == nullptr) { + return remainder; + } + + m_cond = (tse_conds *)tse_alloc_buf(&m_tch, sizeof(tse_conds)); + if (m_cond == nullptr) { + tse_log_warning("alloc shm mem failed, m_cond size(%lu), pushdown cond is null.", sizeof(tse_conds)); + return remainder; + } + + bool no_backslash = false; + if (thd->variables.sql_mode & MODE_NO_BACKSLASH_ESCAPES) { + no_backslash = true; + } + Field **field = table->field; + if (tse_fill_conds(m_tch, m_pushed_conds, field, m_cond, no_backslash) != CT_SUCCESS) { + free_m_cond(m_tch, &m_cond); + m_pushed_conds = nullptr; + m_remainder_conds = nullptr; + return remainder; + } + + pushed_cond = m_pushed_conds; + m_remainder_conds = const_cast(cond); + return remainder; } @@ -5344,26 +5379,26 @@ const Item *ha_tse::cond_push(const Item *cond, bool other_tbls_ok MY_ATTRIBUTE( int ha_tse::engine_push(AQP::Table_access *table_aqp) { DBUG_TRACE; - const Item *cond = table_aqp->get_condition(); assert(m_cond == nullptr); + // Filter Multi-Table Queries + const AQP::Join_plan *const plan = table_aqp->get_join_plan(); + if (plan->get_access_count() > 1) { + return 0; + } + THD *const thd = table->in_use; if (!thd->optimizer_switch_flag(OPTIMIZER_SWITCH_ENGINE_CONDITION_PUSHDOWN)) { return 0; } - if (thd->lex->all_query_blocks_list && thd->lex->all_query_blocks_list->is_recursive()) { return 0; } + const Item *cond = table_aqp->get_condition(); if (cond == nullptr) { return 0; } - // Filter Multi-Table Queries - const AQP::Join_plan *const plan = table_aqp->get_join_plan(); - if (plan->get_access_count() > 1) { - return 0; - } prep_cond_push(cond); if (m_pushed_conds == nullptr) { diff --git a/storage/tianchi/tse_cbo.cc b/storage/tianchi/tse_cbo.cc index d6b12119a4191ca22455deed0cebe80dd3fcdedf..c3d4ca9cbfe9293ba34c8f6ad3da67baf52cbeea 100644 --- a/storage/tianchi/tse_cbo.cc +++ b/storage/tianchi/tse_cbo.cc @@ -546,6 +546,10 @@ void tse_index_stats_update(TABLE *table, tianchi_cbo_stats_t *cbo_stats) uint32_t *n_diff = cbo_stats->ndv_keys; uint32_t records; uint32_t table_part_num = cbo_stats->part_cnt == 0 ? 1 : cbo_stats->part_cnt; + + if (cbo_stats->records == 0) { + return; + } for (uint32 i = 0; i < table->s->keys; i++) { sk = table->key_info[i];