From 1f71d1e043b82470c95c58c6fec6a27320b256a6 Mon Sep 17 00:00:00 2001 From: hewenxun Date: Tue, 18 Jun 2024 16:36:38 +0800 Subject: [PATCH 1/4] Performance Optimization --- storage/tianchi/ha_tse.cc | 53 ++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 703d903..3b26b16 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) { -- Gitee From 8e9a8ffc4cc66bb803a2b55dd70477d65a2c9078 Mon Sep 17 00:00:00 2001 From: yuanyazhi Date: Thu, 20 Jun 2024 20:24:34 +0800 Subject: [PATCH 2/4] fix cond --- storage/tianchi/tse_util.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/storage/tianchi/tse_util.cc b/storage/tianchi/tse_util.cc index 4d8619d..96a3913 100644 --- a/storage/tianchi/tse_util.cc +++ b/storage/tianchi/tse_util.cc @@ -528,9 +528,7 @@ int dfs_fill_conds(tianchi_handler_t m_tch, Item *items, Field **field, tse_cond } memset(list, 0, sizeof(tse_cond_list)); ret = tse_push_cond_list(m_tch, items, field, list, no_backslash); - if (ret == CT_SUCCESS) { - conds->cond_list = list; - } + conds->cond_list = list; break; case TSE_NOT_FUNC: case TSE_XOR_FUNC: @@ -541,9 +539,7 @@ int dfs_fill_conds(tianchi_handler_t m_tch, Item *items, Field **field, tse_cond } memset(list, 0, sizeof(tse_cond_list)); ret = tse_push_cond_args(m_tch, items, field, list, no_backslash); - if (ret == CT_SUCCESS) { - conds->cond_list = list; - } + conds->cond_list = list; break; case TSE_EQ_FUNC: case TSE_EQUAL_FUNC: -- Gitee From 687bab3f8f845c95567b12bff87d8e0841bf6974 Mon Sep 17 00:00:00 2001 From: xicoding Date: Sat, 22 Jun 2024 19:51:34 +0800 Subject: [PATCH 3/4] Revert "fix cond" This reverts commit 8e9a8ffc4cc66bb803a2b55dd70477d65a2c9078. --- storage/tianchi/tse_util.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/tianchi/tse_util.cc b/storage/tianchi/tse_util.cc index 96a3913..4d8619d 100644 --- a/storage/tianchi/tse_util.cc +++ b/storage/tianchi/tse_util.cc @@ -528,7 +528,9 @@ int dfs_fill_conds(tianchi_handler_t m_tch, Item *items, Field **field, tse_cond } memset(list, 0, sizeof(tse_cond_list)); ret = tse_push_cond_list(m_tch, items, field, list, no_backslash); - conds->cond_list = list; + if (ret == CT_SUCCESS) { + conds->cond_list = list; + } break; case TSE_NOT_FUNC: case TSE_XOR_FUNC: @@ -539,7 +541,9 @@ int dfs_fill_conds(tianchi_handler_t m_tch, Item *items, Field **field, tse_cond } memset(list, 0, sizeof(tse_cond_list)); ret = tse_push_cond_args(m_tch, items, field, list, no_backslash); - conds->cond_list = list; + if (ret == CT_SUCCESS) { + conds->cond_list = list; + } break; case TSE_EQ_FUNC: case TSE_EQUAL_FUNC: -- Gitee From fa14b29c98e4123bf2aab7ec15bf8e38df057fc0 Mon Sep 17 00:00:00 2001 From: xicoding Date: Sat, 22 Jun 2024 19:51:45 +0800 Subject: [PATCH 4/4] Revert "Performance Optimization" This reverts commit 1f71d1e043b82470c95c58c6fec6a27320b256a6. --- storage/tianchi/ha_tse.cc | 53 +++++++-------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 3b26b16..703d903 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -5309,45 +5309,10 @@ 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 = 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); - + const Item *remainder; + remainder = cond; return remainder; } @@ -5379,26 +5344,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) { -- Gitee