[英]MySQL Update a Complete Column data from Another Table with same Primary Key (30 Million Row)
I have two tables: Final and Primary in my MySQL database. 我有两个表:MySQL数据库中的Final和Primary。 Final Table:
决赛桌:
UID (Primary Key), Surface (Varchar), BCD_Value (Int , Index), Env_Value (Int)
Primary Table: 主表:
UID (Primary Key), BCD_Value (Int , Index)
There are 30 Million rows in each table. 每个表中有3000万行。 Primary Table has the correct BCD_Value.
主表具有正确的BCD_Value。 I have to update Final Table's BCD_Value with values from Primary on matching UID.
我必须用匹配UID上Primary的值更新Final Table的BCD_Value。
I was using following in MySQL command line 我在MySQL命令行中使用以下命令
update Primary pri, Final fin set fn.BCD_Value = pri.BCD_Value where fin.UID = pri.UID
But it does nothing after 36 hours. 但是36小时后它什么也没做。
Further, I have implemented a code in perl which creates update statement for 5000 rows at time (loops it for 30 million/ 5000 times). 此外,我在perl中实现了一个代码,该代码一次创建了5000行的更新语句(循环了3000万/ 5000次)。 Now it is working but I desperately need to fasten it.
现在它正在工作,但我非常需要将其固定。
try converting into ANSI SQL-92
syntax 尝试转换为
ANSI SQL-92
语法
UPDATE Final fin INNER JOIN `Primary` pri
ON fin.UID = pri.UID
SET fn.BCD_Value = pri.BCD_Value
it takes time to update all records because it updates the indexes as well. 更新所有记录需要花费时间,因为它也会同时更新索引。
try removing the index on Final.BCD_Value
first then add again after the update has been made. 请尝试先删除
Final.BCD_Value
上的索引,然后在进行更新后再次添加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.