diff --git a/storage/tianchi/ha_tse.cc b/storage/tianchi/ha_tse.cc index 703d903a01b89245b541d067128db1c79ee35be8..67dabd96078cb001a9d5c8ef350b16f616ec6d11 100644 --- a/storage/tianchi/ha_tse.cc +++ b/storage/tianchi/ha_tse.cc @@ -106,6 +106,9 @@ #include "sql/dd/upgrade/server.h" // UPGRADE_FORCE #include "sql/abstract_query_plan.h" +#include "sql/dd/properties.h" +#include "sql/dd/types/partition.h" + #include "tse_stats.h" #include "tse_error.h" #include "tse_log.h" @@ -117,6 +120,7 @@ #include "sql/mysqld.h" #include "sql/plugin_table.h" #include "sql/dd/object_id.h" +#include "sql/dd/string_type.h" #include "sql/dd/cache/dictionary_client.h" #include "sql/dd/dd_schema.h" #include "sql/sql_table.h" @@ -775,7 +779,10 @@ bool ha_tse::check_unsupported_operation(THD *thd, HA_CREATE_INFO *create_info) my_error(ER_NOT_ALLOWED_COMMAND, MYF(0)); return HA_ERR_UNSUPPORTED; } - + if (create_info != nullptr && create_info->index_file_name) { + my_error(ER_ILLEGAL_HA, MYF(0), table_share != nullptr ? table_share->table_name.str : " "); + return true; + } return false; } diff --git a/storage/tianchi/ha_tse.h b/storage/tianchi/ha_tse.h index 9cdeedb73b2a535c6119c3f6cb761b39af3d4548..33ec26a7b75ecacc28db19a700b51ca64834dc5f 100644 --- a/storage/tianchi/ha_tse.h +++ b/storage/tianchi/ha_tse.h @@ -36,6 +36,7 @@ #include "sql/abstract_query_plan.h" #include "sql/dd/types/schema.h" #include "sql/dd/types/object_table_definition.h" +#include "sql/dd/string_type.h" #pragma GCC visibility push(default) @@ -148,6 +149,7 @@ again. */ #define IS_PRIMARY_ROLE() (tse_get_cluster_role() == (int32_t)dis_cluster_role::PRIMARY) #define IS_STANDBY_ROLE() (tse_get_cluster_role() == (int32_t)dis_cluster_role::STANDBY) +static const dd::String_type index_file_name_val_key("index_file_name"); static const uint ROW_ID_LENGTH = sizeof(uint64_t); static const uint TSE_START_TIMEOUT = 120; // seconds extern const char *tse_hton_name; diff --git a/storage/tianchi/ha_tsepart.cc b/storage/tianchi/ha_tsepart.cc index dc0ad9ca86d2be7a1ffbfab787e5a057c5af2947..f9063937862cc65f9689fefe23696f0541008fb3 100644 --- a/storage/tianchi/ha_tsepart.cc +++ b/storage/tianchi/ha_tsepart.cc @@ -53,6 +53,9 @@ #include "typelib.h" #include "tse_cbo.h" #include "sql/sql_alter.h" +#include "sql/dd/properties.h" +#include "sql/dd/types/partition.h" +#include "sql/dd/string_type.h" #define INVALID_PART_ID (uint32)0xFFFFFFFF; @@ -1130,3 +1133,32 @@ uint32 ha_tsepart::calculate_key_hash_value(Field **field_array) return (Partition_helper::ph_calculate_key_hash_value(field_array)); } +bool ha_tsepart::check_unsupported_index(dd::Table *table_def) { + // 遍历分区,存在index_file_name_val,创建表失败 + for (const auto dd_part : *table_def->leaf_partitions()) { + dd::String_type index_file_name; + if(dd_part == nullptr){ + continue; + } + const dd::Properties &options = dd_part->options(); + if (options.exists(index_file_name_val_key)) { + options.get(index_file_name_val_key, &index_file_name); + } + if (!index_file_name.empty()) { + my_error(ER_ILLEGAL_HA, MYF(0), table_share != nullptr ? table_share->table_name.str : " "); + return true; + } + } + return false; +} + +EXTER_ATTACK int ha_tsepart::create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, + dd::Table *table_def) { + THD *thd = ha_thd(); + if(table_def != nullptr && check_unsupported_index(table_def)){ + tse_log_system("Unsupported operation. sql = %s", thd->query().str); + return HA_ERR_WRONG_COMMAND; + } + return ha_tse::create(name, form, create_info, table_def); +} + diff --git a/storage/tianchi/ha_tsepart.h b/storage/tianchi/ha_tsepart.h index 0cb07598720f23133f582e2fed514bc1518a1ff7..ed534549cb82dde42815e9e6fe7074104d379cd7 100644 --- a/storage/tianchi/ha_tsepart.h +++ b/storage/tianchi/ha_tsepart.h @@ -24,6 +24,7 @@ #include "tse_srv.h" #include "tse_util.h" #include "sql/partitioning/partition_handler.h" +#include "sql/dd/string_type.h" class Tsepart_share : public Partition_share { public: @@ -64,6 +65,8 @@ class ha_tsepart : public ha_tse, */ int truncate_partition_low(dd::Table *dd_table) override; + bool check_unsupported_index(dd::Table *table_def); + /** Write a row in specific partition. Stores a row in an TSE database, to the table specified in this handle. @@ -368,6 +371,9 @@ class ha_tsepart : public ha_tse, int optimize(THD *thd, HA_CHECK_OPT *check_opt) override; + int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, + dd::Table *table_def) override; + /* Get partition row type @param[in] partition_table partition table @param[in] part_id Id of partition for which row type to be retrieved diff --git a/storage/tianchi/tse_cbo.cc b/storage/tianchi/tse_cbo.cc index d6b12119a4191ca22455deed0cebe80dd3fcdedf..eaf20f88351ef4f1608b0bfcb32edb37a61cace0 100644 --- a/storage/tianchi/tse_cbo.cc +++ b/storage/tianchi/tse_cbo.cc @@ -550,11 +550,20 @@ void tse_index_stats_update(TABLE *table, tianchi_cbo_stats_t *cbo_stats) for (uint32 i = 0; i < table->s->keys; i++) { sk = table->key_info[i]; for (uint32 j = 0; j < sk.actual_key_parts; j++) { + bool all_n_diff_is_zero = true; rec_per_key = 0.0f; for (uint32 k = 0; k < table_part_num; k++) { records = cbo_stats->tse_cbo_stats_table[k].estimate_rows; if (*(n_diff + i * MAX_KEY_COLUMNS + j) > 0) { rec_per_key += static_cast(records) / static_cast(*(n_diff + i * MAX_KEY_COLUMNS + j)); + all_n_diff_is_zero = false; + } + } + + // if all n_diff(s) values 0, take records itself as rec_per_key + if (all_n_diff_is_zero) { + for (uint32 k = 0; k < table_part_num; k++) { + rec_per_key += static_cast(cbo_stats->tse_cbo_stats_table[k].estimate_rows); } }