diff options
author | Sergei Golubchik <serg@mariadb.org> | 2022-05-09 22:04:06 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2022-05-09 22:04:06 +0200 |
commit | ef781162ff2eb97f405b19dc150ab674e91dbc05 (patch) | |
tree | 63b897dece50ab65652174af4cd0aabd8f3a8505 /sql/partition_info.cc | |
parent | e9af6b2a4d8750c32d4953f08f8bc5f2e33cb9e3 (diff) | |
parent | 16cebed54065ad9e18953aa86d48f6007d53c2d3 (diff) | |
download | mariadb-git-ef781162ff2eb97f405b19dc150ab674e91dbc05.tar.gz |
Merge branch '10.4' into 10.5
Diffstat (limited to 'sql/partition_info.cc')
-rw-r--r-- | sql/partition_info.cc | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 3c74fd4b9c7..d2b7a09c606 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -819,6 +819,9 @@ bool partition_info::has_unique_name(partition_element *element) */ int partition_info::vers_set_hist_part(THD *thd) { + if (!vers_require_hist_part(thd)) + return 0; + if (table->pos_in_table_list && table->pos_in_table_list->partition_names) { @@ -827,12 +830,10 @@ int partition_info::vers_set_hist_part(THD *thd) if (vers_info->limit) { ha_partition *hp= (ha_partition*)(table->file); - partition_element *next= NULL; + partition_element *next; List_iterator<partition_element> it(partitions); - while (next != vers_info->hist_part) - next= it++; - DBUG_ASSERT(bitmap_is_set(&read_partitions, next->id)); - ha_rows records= hp->part_records(next); + ha_rows records= 0; + vers_info->hist_part= partitions.head(); while ((next= it++) != vers_info->now_part) { DBUG_ASSERT(bitmap_is_set(&read_partitions, next->id)); @@ -842,17 +843,8 @@ int partition_info::vers_set_hist_part(THD *thd) vers_info->hist_part= next; records= next_records; } - if (records >= vers_info->limit) - { - if (next == vers_info->now_part) - { - my_error(WARN_VERS_PART_FULL, MYF(ME_WARNING|ME_ERROR_LOG), - table->s->db.str, table->s->table_name.str, - vers_info->hist_part->partition_name, "LIMIT"); - } - else - vers_info->hist_part= next; - } + if (records >= vers_info->limit && next != vers_info->now_part) + vers_info->hist_part= next; return 0; } @@ -877,6 +869,45 @@ int partition_info::vers_set_hist_part(THD *thd) } +/** + Warn at the end of DML command if the last history partition is out of LIMIT. +*/ +void partition_info::vers_check_limit(THD *thd) +{ + if (!vers_info->limit || + vers_info->hist_part->id + 1 < vers_info->now_part->id) + return; + + /* + NOTE: at this point read_partitions bitmap is already pruned by DML code, + we have to set read bits for working history partition. We could use + bitmap_set_all(), but this is not optimal since there can be quite a number + of partitions. + */ + const uint32 sub_factor= num_subparts ? num_subparts : 1; + uint32 part_id= vers_info->hist_part->id * sub_factor; + const uint32 part_id_end= part_id + sub_factor; + DBUG_ASSERT(part_id_end <= num_parts * sub_factor); + for (; part_id < part_id_end; ++part_id) + bitmap_set_bit(&read_partitions, part_id); + + ha_partition *hp= (ha_partition*)(table->file); + ha_rows hist_rows= hp->part_records(vers_info->hist_part); + if (hist_rows >= vers_info->limit) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + WARN_VERS_PART_FULL, + ER_THD(thd, WARN_VERS_PART_FULL), + table->s->db.str, table->s->table_name.str, + vers_info->hist_part->partition_name, "LIMIT"); + + sql_print_warning(ER_THD(thd, WARN_VERS_PART_FULL), + table->s->db.str, table->s->table_name.str, + vers_info->hist_part->partition_name, "LIMIT"); + } +} + + /* Check that the partition/subpartition is setup to use the correct storage engine |