From f1beb2581bae7d272bac406b817125f6e322b11b Mon Sep 17 00:00:00 2001 From: hopebo Date: Mon, 8 Nov 2021 19:10:45 +0800 Subject: [PATCH] Bugfix Empty loop when pruning partitions for INSERT command --- sql/sql_insert.cc | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 4c2573584af..0fcbb718096 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1472,7 +1472,8 @@ bool Sql_cmd_insert_base::prepare_inner(THD *thd) { if (thd->is_error()) return true; } - while (its != insert_many_values.end()) { + while (its != insert_many_values.end() && + can_prune_partitions == partition_info::PRUNE_YES) { const mem_root_deque *values = *its++; counter++; @@ -1483,23 +1484,21 @@ bool Sql_cmd_insert_base::prepare_inner(THD *thd) { TODO: Cache the calculated part_id and reuse in ha_partition::write_row() if possible. */ - if (can_prune_partitions == partition_info::PRUNE_YES) { - if (insert_table->part_info->set_used_partition( - thd, insert_field_list, *values, info, - prune_needs_default_values, &used_partitions)) { + if (insert_table->part_info->set_used_partition( + thd, insert_field_list, *values, info, + prune_needs_default_values, &used_partitions)) { + can_prune_partitions = partition_info::PRUNE_NO; + // set_used_partition may fail. + if (thd->is_error()) return true; + } + if (!(counter % num_partitions)) { + /* + Check if we using all partitions in table after adding partition + for current row to the set of used partitions. Do it only from + time to time to avoid overhead from bitmap_is_set_all() call. + */ + if (bitmap_is_set_all(&used_partitions)) can_prune_partitions = partition_info::PRUNE_NO; - // set_used_partition may fail. - if (thd->is_error()) return true; - } - if (!(counter % num_partitions)) { - /* - Check if we using all partitions in table after adding partition - for current row to the set of used partitions. Do it only from - time to time to avoid overhead from bitmap_is_set_all() call. - */ - if (bitmap_is_set_all(&used_partitions)) - can_prune_partitions = partition_info::PRUNE_NO; - } } } } -- 2.19.1.3.ge56e4f7