如何在订阅者表中迁移4百万条记录来分离mysql中的40个表?

时间:2014-07-07 12:18:07

标签: mysql sql database database-design procedure

我在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

1 个答案:

答案 0 :(得分:1)

这称为 Partitionning ,MySQL可以为您完成这项工作:

ALTER TABLE your_table PARTITION BY KEY(some_column_here) PARTITIONS 40;

然而,4M行毕竟不是 ,你可能只缺少email上的索引。