Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将subscribers_表中的400万条记录迁移到mysql中的40个表中?_Mysql_Sql_Database_Database Design_Procedure - Fatal编程技术网

如何将subscribers_表中的400万条记录迁移到mysql中的40个表中?

如何将subscribers_表中的400万条记录迁移到mysql中的40个表中?,mysql,sql,database,database-design,procedure,Mysql,Sql,Database,Database Design,Procedure,我在subscribers_表中有大量的数据记录,大约4200000条记录,当我通过电子邮件选择一个用户时需要很长时间,现在我不想删除这些记录,我需要处理单独的表,如subscribers_表1,subscribers_表2,表42 现在我需要在mysql中定义一个过程,将subscribers\u表中的数据孔移动到单独的表中subscribers\u table1、subscribers\u table2、…、subscribers\u table42 以下代码为伪代码: table_numb

我在subscribers_表中有大量的数据记录,大约4200000条记录,当我通过电子邮件选择一个用户时需要很长时间,现在我不想删除这些记录,我需要处理单独的表,如subscribers_表1,subscribers_表2,表42

现在我需要在mysql中定义一个过程,将subscribers\u表中的数据孔移动到单独的表中subscribers\u table1、subscribers\u table2、…、subscribers\u 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
这叫做,MySQL可以为您完成这项工作:

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

然而,毕竟400万行并没有那么大,也许您所缺少的只是
电子邮件上的索引

顺便说一句,我认为这是一个非常糟糕的解决方案。您打算如何恢复混乱中的任何数据?4200000不够大,无法破坏您的系统。在尝试您在这里描述的“解决方案”之前,您应该使用索引或在您的方案中做出更好的决策。我同意,但是这个系统正在联机工作,我无法修改代码来解决问题,我需要这种方法将它们分为42个表。您不需要这样的东西。您在电子邮件字段上有索引吗?@TárekKala'ajy您可以为mysql数据库设置索引,而不会在系统中停机。您可以运行解释查询,告诉您解决此问题的更好方法。一些参考资料:非常感谢@DanBracukI,我认为分区只有在您将记录保存在不同的物理设备上时才有用。编制数据索引是正确的做法分区允许一些优化,这意味着操作较小的数据集(和较小的索引)。因此,这可能在一定程度上有所帮助。但显然,正确的索引绝对是最重要的因素。