diff --git a/storage/tianchi/datatype_cnvrtr.cc b/storage/tianchi/datatype_cnvrtr.cc index d1e89ac7035ef0b815452e9fcedf6f17b229911e..09f62222e99cc6cbf6c9a07787f721fa65085c54 100644 --- a/storage/tianchi/datatype_cnvrtr.cc +++ b/storage/tianchi/datatype_cnvrtr.cc @@ -1656,6 +1656,13 @@ static inline bool ctc_field_type_is_lob(bool is_index_only, const field_cnvrt_a !tch.read_only_in_ct)); } +bool tse_is_field_lob(Field *field) +{ + const field_cnvrt_aux_t *cnvrt_aux = get_auxiliary_for_field_convert(field, field->type()); + return (cnvrt_aux->mysql_field_type == MYSQL_TYPE_BLOB || cnvrt_aux->mysql_field_type == MYSQL_TYPE_JSON || + ((cnvrt_aux->mysql_field_type == MYSQL_TYPE_VARCHAR) && VARCHAR_AS_BLOB(field->row_pack_length()))); +} + static bool ctc_update_offset_single(uint col_id, Field *field, uint8 cantian_col_type, const field_cnvrt_aux_t* cnvrt_aux, record_info_t *record_info, record_buf_info_t *record_buf, field_offset_and_len_t *size, bool is_index_only, tianchi_handler_t &tch) { diff --git a/storage/tianchi/datatype_cnvrtr.h b/storage/tianchi/datatype_cnvrtr.h index 21516aa7ffe3c440c45513617c361bc3e176b3bf..1488081aae158c058a5123e7ea1679014bb2042c 100644 --- a/storage/tianchi/datatype_cnvrtr.h +++ b/storage/tianchi/datatype_cnvrtr.h @@ -65,6 +65,7 @@ typedef int64 date_t; #define VARCHAR_AS_BLOB(len) ((len) > TSE_DDL_MAX_VARCHAR_COLUMN_SIZE) #define CM_ALL_ZERO_DATETIME ((date_t)-63113904000000000LL) /* == cm_encode_date(00-00-00 00:00:00.000000) */ +bool tse_is_field_lob(Field *field); longlong bit_cnvt_mysql_cantian(const uchar *ptr, Field *mysql_field); void bit_cnvt_cantian_mysql(const uchar *cantian_ptr, uchar *mysql_ptr, Field *mysql_field); enum enum_sql_data_types diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 05ab5b8ed212be492d84f9794c02591daab4b4d5..a7218f91e09d5d15e8ef7efba158ea1718967647 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -3041,7 +3041,7 @@ void ha_tse::update_blob_addrs(uchar *record) { continue; } - if (table->field[field_no]->is_virtual_gcol()) { + if (tse_field_no_stats(table->field[field_no])) { continue; } @@ -5345,9 +5345,8 @@ tse_select_mode_t ha_tse::get_select_mode() return mode; } -int alloc_str_mysql_mem(tianchi_cbo_stats_t *cbo_stats, uint32_t part_num, TABLE *table) +int alloc_str_mysql_mem(tianchi_cbo_stats_t *cbo_stats, uint32_t part_num, TABLE *table, uint32_t num_cols) { - uint32_t num_cols = table->s->fields - table->s->vfields; cbo_stats->is_str_col =(bool *)my_malloc(PSI_NOT_INSTRUMENTED, num_cols * sizeof(bool), MYF(MY_WME)); if (cbo_stats->is_str_col == nullptr) { tse_log_error("alloc shm mem failed, cbo_stats->is_str_col(%lu)", num_cols * sizeof(bool)); @@ -5358,7 +5357,7 @@ int alloc_str_mysql_mem(tianchi_cbo_stats_t *cbo_stats, uint32_t part_num, TABLE uint col_id = 0; for (uint i = 0; i < table->s->fields; i++) { Field *field = table->field[i]; - if (field->is_virtual_gcol()) { + if (tse_field_no_stats(field)) { continue; } if (field->real_type() == MYSQL_TYPE_VARCHAR || field->real_type() == MYSQL_TYPE_VAR_STRING || @@ -5379,7 +5378,7 @@ int alloc_str_mysql_mem(tianchi_cbo_stats_t *cbo_stats, uint32_t part_num, TABLE for (uint i = 0; i < part_num; i++) { for (uint j = 0; j < table->s->fields; j++) { Field *field = table->field[j]; - if (field->is_virtual_gcol()) { + if (tse_field_no_stats(field)) { continue; } if (field->real_type() == MYSQL_TYPE_VARCHAR || field->real_type() == MYSQL_TYPE_VAR_STRING || @@ -5407,14 +5406,15 @@ int ha_tse::initialize_cbo_stats() tse_log_error("alloc mem failed, m_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); return ERR_ALLOC_MEMORY; } - *m_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr, nullptr, nullptr}; + *m_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, 0, 0, nullptr, nullptr, nullptr, nullptr}; m_share->cbo_stats->tse_cbo_stats_table = (tse_cbo_stats_table_t*)my_malloc(PSI_NOT_INSTRUMENTED, sizeof(tse_cbo_stats_table_t), MYF(MY_WME)); if (m_share->cbo_stats->tse_cbo_stats_table == nullptr) { tse_log_error("alloc mem failed, m_share->cbo_stats->tse_cbo_stats_table(%lu)", sizeof(tse_cbo_stats_table_t)); return ERR_ALLOC_MEMORY; } - uint32_t num_cols = table->s->fields - table->s->vfields; + uint32_t num_cols = tse_stats_col_num(table->s->field, table->s->fields); + m_share->cbo_stats->num_stats_cols = num_cols; m_share->cbo_stats->col_ptr = (tse_cbo_stats_column_t*)my_malloc(PSI_NOT_INSTRUMENTED, num_cols * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); if (m_share->cbo_stats->col_ptr == nullptr) { @@ -5429,7 +5429,7 @@ int ha_tse::initialize_cbo_stats() tse_cbo_stats_column_t *columns = m_share->cbo_stats->col_ptr; for (uint col_id = 0; col_id < table->s->fields; col_id++) { - if (table->s->field[col_id]->is_virtual_gcol()) { + if (tse_field_no_stats(table->s->field[col_id])) { m_share->cbo_stats->tse_cbo_stats_table->columns[col_id] = nullptr; } else { m_share->cbo_stats->tse_cbo_stats_table->columns[col_id] = columns; @@ -5438,7 +5438,7 @@ int ha_tse::initialize_cbo_stats() } } - ct_errno_t ret = (ct_errno_t)alloc_str_mysql_mem(m_share->cbo_stats, 1, table); + ct_errno_t ret = (ct_errno_t)alloc_str_mysql_mem(m_share->cbo_stats, 1, table, num_cols); if (ret != CT_SUCCESS) { tse_log_error("m_share:tse alloc str mysql mem failed, ret:%d", ret); } diff --git a/storage/tianchi/ha_tse.h b/storage/tianchi/ha_tse.h index 072c9ab4eada68a0c89cfee61237e601f45ff38d..5847c0deb6678a01b74f8a88c6e2ad28eec0b8db 100644 --- a/storage/tianchi/ha_tse.h +++ b/storage/tianchi/ha_tse.h @@ -997,7 +997,7 @@ int32_t tse_get_cluster_role(); void tse_set_mysql_read_only(); void tse_reset_mysql_read_only(); -int alloc_str_mysql_mem(tianchi_cbo_stats_t *cbo_stats, uint32_t part_num, TABLE *table); +int alloc_str_mysql_mem(tianchi_cbo_stats_t *cbo_stats, uint32_t part_num, TABLE *table, uint32_t num_cols); void free_columns_cbo_stats(tse_cbo_stats_column_t *tse_cbo_stats_columns, bool *is_str_first_addr, TABLE *table); int32_t ctc_get_shm_file_num(uint32_t *shm_file_num); int32_t ctc_get_shm_usage(uint32_t *ctc_shm_usage); diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index bf24b12c4035c2c177a6afb486a4fb85b7ef7881..e91b030e562ebc59bd0bce0d5cdd8f0c39804e6f 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -1012,7 +1012,7 @@ int ha_tsepart::initialize_cbo_stats() { tse_log_error("alloc mem failed, m_part_share->cbo_stats size(%lu)", sizeof(tianchi_cbo_stats_t)); return ERR_ALLOC_MEMORY; } - *m_part_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, 0, nullptr, nullptr, nullptr, nullptr}; + *m_part_share->cbo_stats = {0, 0, 0, 0, 0, nullptr, 0, 0, nullptr, nullptr, nullptr, nullptr}; m_part_share->cbo_stats->part_cnt = part_num; @@ -1028,7 +1028,8 @@ int ha_tsepart::initialize_cbo_stats() { tse_log_error("alloc mem failed, m_part_share->cbo_stats->ndv_keys size(%lu)", table->s->keys * sizeof(uint32_t) * MAX_KEY_COLUMNS); return ERR_ALLOC_MEMORY; } - uint32_t num_cols = table->s->fields - table->s->vfields; + uint32_t num_cols = tse_stats_col_num(table->s->field, table->s->fields); + m_part_share->cbo_stats->num_stats_cols = num_cols; m_part_share->cbo_stats->col_ptr = (tse_cbo_stats_column_t *)my_malloc(PSI_NOT_INSTRUMENTED, part_num * num_cols * sizeof(tse_cbo_stats_column_t), MYF(MY_WME)); if (m_part_share->cbo_stats->col_ptr == nullptr) { tse_log_error("alloc mem failed, m_share->cbo_stats->tse_cbo_stats_table->columns size(%lu)", part_num * num_cols * sizeof(tse_cbo_stats_column_t)); @@ -1045,7 +1046,7 @@ int ha_tsepart::initialize_cbo_stats() { return ERR_ALLOC_MEMORY; } for (uint col_id = 0; col_id < table->s->fields; col_id++) { - if (table->s->field[col_id]->is_virtual_gcol()) { + if (tse_field_no_stats(table->s->field[col_id])) { m_part_share->cbo_stats->tse_cbo_stats_table[i].columns[col_id] = nullptr; } else { m_part_share->cbo_stats->tse_cbo_stats_table[i].columns[col_id] = columns; @@ -1055,7 +1056,7 @@ int ha_tsepart::initialize_cbo_stats() { } } - ct_errno_t ret = (ct_errno_t)alloc_str_mysql_mem(m_part_share->cbo_stats, part_num, table); + ct_errno_t ret = (ct_errno_t)alloc_str_mysql_mem(m_part_share->cbo_stats, part_num, table, num_cols); if (ret != CT_SUCCESS) { tse_log_error("m_part_share:tse alloc str mysql mem failed, ret:%d", ret); } diff --git a/storage/tianchi/tse_cbo.cc b/storage/tianchi/tse_cbo.cc index 11f126cf9c0eac696821fd703f37755c18cfefd8..a60aff0a77907a48c4af05a81945f1108107a68e 100644 --- a/storage/tianchi/tse_cbo.cc +++ b/storage/tianchi/tse_cbo.cc @@ -628,7 +628,7 @@ double calc_density_one_table(uint16_t idx_id, tse_range_key *key, if (col_map & ((uint64_t)1 << idx_col_num)) { KEY_PART_INFO cur_index_part = cur_index.key_part[idx_col_num]; col_id = cur_index_part.field->field_index(); - if (cur_index_part.field->is_virtual_gcol()) { + if (tse_field_no_stats(cur_index_part.field)) { continue; } uint32_t offset = cur_index_part.field->is_nullable() ? 1 : 0; @@ -676,7 +676,7 @@ void tse_index_stats_update(TABLE *table, tianchi_cbo_stats_t *cbo_stats) bool all_n_diff_is_zero = true; rec_per_key = 0.0f; Field *field = sk.key_part[j].field; - if (field->is_virtual_gcol()) { + if (tse_field_no_stats(field)) { continue; } uint32 fld_idx = field->field_index(); @@ -707,3 +707,19 @@ void tse_index_stats_update(TABLE *table, tianchi_cbo_stats_t *cbo_stats) } } } + +bool tse_field_no_stats(Field *field) +{ + return (tse_is_field_lob(field) || field->is_virtual_gcol()); +} + +uint32_t tse_stats_col_num(Field **field, uint32_t num_fields) +{ + uint32_t num_cols = num_fields; + for (uint col_id = 0; col_id < num_fields; col_id++) { + if (tse_field_no_stats(field[col_id])) { + num_cols -= 1; + } + } + return num_cols; +} \ No newline at end of file diff --git a/storage/tianchi/tse_cbo.h b/storage/tianchi/tse_cbo.h index 080e0731b37e6b4e2cc8968a49f990a14d1aad75..aa0c5b623c9774362ac0dd8f664777dcdad83944 100644 --- a/storage/tianchi/tse_cbo.h +++ b/storage/tianchi/tse_cbo.h @@ -74,4 +74,6 @@ double calc_density_one_table(uint16_t idx_id, tse_range_key *key, tse_cbo_stats_table_t *cbo_stats, const TABLE &table); void tse_index_stats_update(TABLE *table, tianchi_cbo_stats_t *cbo_stats); +bool tse_field_no_stats(Field *field); +uint32_t tse_stats_col_num(Field **field, uint32_t num_fields); #endif diff --git a/storage/tianchi/tse_srv.h b/storage/tianchi/tse_srv.h index b757d825e7666349cc6ea0e87c7a5ffb2e6410a0..4d1c641c0a9a7af04e22e680bf4217607f5c22b6 100644 --- a/storage/tianchi/tse_srv.h +++ b/storage/tianchi/tse_srv.h @@ -158,6 +158,7 @@ typedef struct { uint32_t records; uint32_t *ndv_keys; uint32_t num_str_cols; + uint32_t num_stats_cols; bool *is_str_col; tse_cbo_stats_column_t *col_ptr; char *str_ptr; diff --git a/storage/tianchi/tse_srv_mq_stub.cc b/storage/tianchi/tse_srv_mq_stub.cc index 698b72fe6ac5e151f81f9022944561d9a15315ad..135e69f23b226d0f54a20397b32d11a7f99962f0 100644 --- a/storage/tianchi/tse_srv_mq_stub.cc +++ b/storage/tianchi/tse_srv_mq_stub.cc @@ -798,6 +798,7 @@ int tse_get_cbo_stats(tianchi_handler_t *tch, tianchi_cbo_stats_t *stats, tse_cb free_share_mem(shm_inst_4_req, req); return ERR_ALLOC_MEMORY; } + req->stats->num_stats_cols = stats->num_stats_cols; req->stats->msg_len = stats->msg_len; uint num_columns = req->stats->msg_len / sizeof(tse_cbo_stats_column_t); req->stats->part_cnt = stats->part_cnt;