summaryrefslogtreecommitdiff
path: root/sql/partition_info.h
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2020-04-27 16:36:03 +0300
committerAleksey Midenkov <midenok@gmail.com>2020-04-27 16:36:03 +0300
commit73aa78ea9d48c433ddb91ef3a7a5b62391d35ac7 (patch)
tree3a4c202d1f413f1a794e08cefd13ae04f353a23c /sql/partition_info.h
parente174fa9d791a1761fc8b2f92a6ab72f44a9dfc33 (diff)
downloadmariadb-git-73aa78ea9d48c433ddb91ef3a7a5b62391d35ac7.tar.gz
MDEV-22155 ALTER add default history partitions name clash on non-default partitions
If any of default names clashes with existing names find next large enough name gap for the requested number of partitions.
Diffstat (limited to 'sql/partition_info.h')
-rw-r--r--sql/partition_info.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/sql/partition_info.h b/sql/partition_info.h
index eb8e53a381a..7ae2d168068 100644
--- a/sql/partition_info.h
+++ b/sql/partition_info.h
@@ -34,6 +34,9 @@ typedef bool (*check_constants_func)(THD *thd, partition_info *part_info);
struct st_ddl_log_memory_entry;
+#define MAX_PART_NAME_SIZE 8
+
+
struct Vers_part_info : public Sql_alloc
{
Vers_part_info() :
@@ -415,6 +418,7 @@ public:
}
return NULL;
}
+ uint next_part_no(uint new_parts) const;
};
uint32 get_next_partition_id_range(struct st_partition_iter* part_iter);
@@ -500,4 +504,46 @@ void partition_info::vers_update_el_ids()
}
}
+
+inline
+bool make_partition_name(char *move_ptr, uint i)
+{
+ int res= snprintf(move_ptr, MAX_PART_NAME_SIZE + 1, "p%u", i);
+ return res < 0 || res > MAX_PART_NAME_SIZE;
+}
+
+
+inline
+uint partition_info::next_part_no(uint new_parts) const
+{
+ if (part_type != VERSIONING_PARTITION)
+ return num_parts;
+ DBUG_ASSERT(new_parts > 0);
+ /* Choose first non-occupied name suffix */
+ uint32 suffix= num_parts - 1;
+ DBUG_ASSERT(suffix > 0);
+ char part_name[MAX_PART_NAME_SIZE + 1];
+ List_iterator_fast<partition_element> it(table->part_info->partitions);
+ for (uint cur_part= 0; cur_part < new_parts; ++cur_part, ++suffix)
+ {
+ uint32 cur_suffix= suffix;
+ if (make_partition_name(part_name, suffix))
+ return 0;
+ partition_element *el;
+ it.rewind();
+ while ((el= it++))
+ {
+ if (0 == my_strcasecmp(&my_charset_latin1, el->partition_name, part_name))
+ {
+ if (make_partition_name(part_name, ++suffix))
+ return 0;
+ it.rewind();
+ }
+ }
+ if (cur_part > 0 && suffix > cur_suffix)
+ cur_part= 0;
+ }
+ return suffix - new_parts;
+}
+
#endif /* PARTITION_INFO_INCLUDED */