我在subscriber_table中拥有大约4,200,000条记录的大量数据记录,当我通过电子邮件选择一个用户时需要很长时间,现在我不想删除这些记录,我需要处理像subscriber_table1,subscribers_table2这样的分离表。 ,...,subscribers_table42
现在我需要在mysql 中使用定义过程,将subscriber_table中的数据漏洞移到分隔的表subscriber_table1,subscribers_table2,...,subscribers_table42 以下代码是伪代码:
table_number = 1
function table_to_migrate_into_separate_tables():
//this loop to read 100,000 record and move to next 100,000 until the end of table
for every 100,000 record in subscribers_table:
//this to create table with nambe (original name + table_number)
Create table("subscribers_table" + table_number)
//this to move 100,000 record only to the created table
Move 100,000 record to table("subscribers_table"+ table_number)
//increase table number to be unique
table_number ++
//this check if subscribers_table has migrate all the records into seperate table then break loop and finish
if subscribers_table has finish:
Break loop
答案 0 :(得分:1)
这称为 Partitionning ,MySQL可以为您完成这项工作:
ALTER TABLE your_table PARTITION BY KEY(some_column_here) PARTITIONS 40;
然而,4M行毕竟不是 ,你可能只缺少email
上的索引。