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

标签 mysql sql database database-design procedure

我在 subscribers_table 中有大约 4,200,000 条记录的大量数据记录,当我通过电子邮件选择一个用户时需要很长时间,现在我不想删除这些记录并且我需要处理单独的表,如 subscribers_table1,subscribers_table2,。 .., subscribers_table42

现在我需要在 mysql 中定义过程 将 subscribers_table 中的数据洞移动到单独的表 subscribers_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

最佳答案

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

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

但是,4M 行毕竟不是那么,也许您缺少的只是电子邮件 上的索引。

关于mysql - 如何将subscribers表中的400万条记录迁移到mysql中的40个表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24610458/

相关文章:

php - 如何在两个Android设备之间传输数据?

MySQL第一次创建数据库报错

c# - 为什么 "SELECT * FROM user"会抛出语法错误?

javascript - Chartjs如何从数据库动态更新数据(Chartjs无法获取数据)

mysql - 在 MySql 中选择一列或三列中的特定列

sql - 如何知道未提交的事务是否试图将特定的唯一键插入 SQL

php - 拉拉维尔。两个表的 Eloquent 查询

java - (可能)数百个移动客户端访问 MySQL 数据库的最佳方式是什么?

java - 更新实体 (JPA+MySQL) - key '142' 的重复条目 'PRIMARY'

PHP运行一次插入sql两次