From a7097944df6dcc0211806ec16f227edd129d7a99 Mon Sep 17 00:00:00 2001 From: solid-yang Date: Thu, 14 Mar 2024 11:26:40 +0800 Subject: [PATCH 1/2] fill right key only in reading range --- .../tianchi/datatype_cnvrt_4_index_search.cc | 4 ++-- .../tianchi/datatype_cnvrt_4_index_search.h | 2 +- storage/tianchi/ha_tse.cc | 22 ++++++++++++++----- storage/tianchi/ha_tse.h | 8 +++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/storage/tianchi/datatype_cnvrt_4_index_search.cc b/storage/tianchi/datatype_cnvrt_4_index_search.cc index 7b61c31..a5b7696 100644 --- a/storage/tianchi/datatype_cnvrt_4_index_search.cc +++ b/storage/tianchi/datatype_cnvrt_4_index_search.cc @@ -94,7 +94,7 @@ static void tse_index_make_up_key_length(int *key, uint8_t **origin_key, uint32_ } int tse_fill_index_key_info(TABLE *table, const uchar *key, uint key_len, const key_range *end_range, - index_key_info_t *index_key_info) { + index_key_info_t *index_key_info, bool is_reading_range) { const uchar *my_key = nullptr; const uchar *end_key = key + key_len; if (end_range != nullptr) { @@ -116,7 +116,7 @@ int tse_fill_index_key_info(TABLE *table, const uchar *key, uint key_len, const &index_key_info->key_info[index_key_info->key_num].left_key_len, &index_key_info->key_info[index_key_info->key_num].is_key_null); - if (end_range != nullptr && my_key < end_range->key + end_range->length) { + if (is_reading_range && end_range != nullptr && my_key < end_range->key + end_range->length) { tse_convert_mysql_key_to_cantian(key_part, my_key, end_range->length, &data_field_len, &index_key_info->key_info[index_key_info->key_num].right_key, &index_key_info->key_info[index_key_info->key_num].right_key_len, diff --git a/storage/tianchi/datatype_cnvrt_4_index_search.h b/storage/tianchi/datatype_cnvrt_4_index_search.h index 831a441..39216bf 100644 --- a/storage/tianchi/datatype_cnvrt_4_index_search.h +++ b/storage/tianchi/datatype_cnvrt_4_index_search.h @@ -20,6 +20,6 @@ #include "decimal_convert.h" int tse_fill_index_key_info(TABLE *table, const uchar *key, uint key_len, const key_range *end_range, - index_key_info_t *index_key_info); + index_key_info_t *index_key_info, bool is_reading_range); int tse_convert_index_datatype(TABLE *table, index_key_info_t *index_key_info, bool has_right_key, dec4_t *data); diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index b8410bd..6ae6d34 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -3493,16 +3493,13 @@ EXTER_ATTACK int ha_tse::index_read(uchar *buf, const uchar *key, uint key_len, int len = strlen(table->key_info[active_index].name); memcpy(index_key_info.index_name, table->key_info[active_index].name, len + 1); - int ret = tse_fill_index_key_info(table, key, key_len, end_range, &index_key_info); + int ret = tse_fill_index_key_info(table, key, key_len, end_range, &index_key_info, m_is_reading_range); if (ret != CT_SUCCESS) { tse_log_error("ha_tse::index_read: fill index key info failed, ret(%d).", ret); return ret; } - bool has_right_key = false; - if (end_range != nullptr && end_range->length != 0) { - has_right_key = true; - } + bool has_right_key = m_is_reading_range && end_range != nullptr && end_range->length != 0; dec4_t d4[MAX_KEY_COLUMNS * 2]; ret = tse_convert_index_datatype(table, &index_key_info, has_right_key, d4); @@ -3544,6 +3541,21 @@ EXTER_ATTACK int ha_tse::index_read_last(uchar *buf, const uchar *key_ptr, uint return index_read(buf, key_ptr, key_len, HA_READ_PREFIX_LAST); } +int ha_tse::read_range_first(const key_range * start_key, const key_range * end_key, + bool eq_range_arg, bool sorted) { + m_is_reading_range = true; + int res = handler::read_range_first(start_key, end_key, eq_range_arg, sorted); + m_is_reading_range = false; + return res; +} + +int ha_tse::read_range_next() { + m_is_reading_range = true; + int res = handler::read_range_next(); + m_is_reading_range = false; + return res; +} + int ha_tse::index_fetch(uchar *buf) { DBUG_TRACE; int mysql_ret = 0; diff --git a/storage/tianchi/ha_tse.h b/storage/tianchi/ha_tse.h index 6e2807a..f8c78ce 100644 --- a/storage/tianchi/ha_tse.h +++ b/storage/tianchi/ha_tse.h @@ -498,6 +498,11 @@ public: int index_fetch(uchar *buf); + int read_range_first(const key_range *start_key, const key_range *end_key, + bool eq_range_arg, bool sorted) override; + + int read_range_next() override; + /** @brief Positions an index cursor to the index specified in the handle. Fetches the @@ -927,6 +932,9 @@ public: Item *m_pushed_conds = nullptr; Item *m_remainder_conds = nullptr; + /** Set to true if we are inside read_range_first() or read_range_next() **/ + bool m_is_reading_range = false; + private: int process_cantian_record(uchar *buf, record_info_t *record_info, ct_errno_t ct_ret, int rc_ret); int bulk_insert(); -- Gitee From 1d69e34ac19f7e1e866996af0c612da138455875 Mon Sep 17 00:00:00 2001 From: solid-yang Date: Thu, 14 Mar 2024 16:42:58 +0800 Subject: [PATCH 2/2] mark skip-scan in index info --- storage/tianchi/ha_tse.cc | 7 +++++++ storage/tianchi/srv_mq_msg.h | 1 + storage/tianchi/tse_srv.h | 1 + storage/tianchi/tse_srv_mq_stub.cc | 1 + 4 files changed, 10 insertions(+) diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 6ae6d34..49cad10 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -3516,6 +3516,13 @@ EXTER_ATTACK int ha_tse::index_read(uchar *buf, const uchar *key, uint key_len, update_member_tch(m_tch, tse_hton, ha_thd()); record_info_t record_info = {tse_buf, 0}; + index_key_info.index_skip_scan = false; + + if ((table->pos_in_table_list->opt_hints_qb) && + (hint_table_state(ha_thd(), table->pos_in_table_list, SKIP_SCAN_HINT_ENUM, OPTIMIZER_SKIP_SCAN))) { + index_key_info.index_skip_scan = true; + } + attachable_trx_update_pre_addr(tse_hton, ha_thd(), &m_tch, true); ct_errno_t ct_ret = (ct_errno_t)tse_index_read(&m_tch, &record_info, &index_key_info, get_select_mode(), m_cond, m_is_replace || m_is_insert_dup); diff --git a/storage/tianchi/srv_mq_msg.h b/storage/tianchi/srv_mq_msg.h index d160605..04fa788 100644 --- a/storage/tianchi/srv_mq_msg.h +++ b/storage/tianchi/srv_mq_msg.h @@ -243,6 +243,7 @@ struct index_read_request { tse_select_mode_t mode; tse_conds *cond; bool is_replace; + bool index_skip_scan; }; struct index_end_request { diff --git a/storage/tianchi/tse_srv.h b/storage/tianchi/tse_srv.h index e3dca7b..6d554d5 100644 --- a/storage/tianchi/tse_srv.h +++ b/storage/tianchi/tse_srv.h @@ -269,6 +269,7 @@ typedef struct { char index_name[TSE_MAX_KEY_NAME_LENGTH + 1]; // 索引名 uint16_t key_num; // 查询条件覆盖多少列 key_info_t key_info[MAX_KEY_COLUMNS]; // 索引查询条件数组 + bool index_skip_scan; } index_key_info_t; enum TSE_FUNC_TYPE { diff --git a/storage/tianchi/tse_srv_mq_stub.cc b/storage/tianchi/tse_srv_mq_stub.cc index 4c8477a..a155082 100644 --- a/storage/tianchi/tse_srv_mq_stub.cc +++ b/storage/tianchi/tse_srv_mq_stub.cc @@ -486,6 +486,7 @@ static void copy_index_info_to_req(const index_key_info_t *index_info, index_rea req->action = index_info->action; req->sorted = index_info->sorted; req->key_num = index_info->key_num; + req->index_skip_scan = index_info->index_skip_scan; memcpy(req->index_name, index_info->index_name, strlen(index_info->index_name) + 1); return; -- Gitee