简体   繁体   English

使用大量数据进行更新查询以避免锁定等待超时的良好做法是什么?

[英]What is the good practice on update query with big volume of data to avoid a lock wait timeout?

So basically, I have this current query :所以基本上,我有这个当前的查询:

UPDATE act AS a
INNER JOIN blok AS b
ON b.fav_pat = a.pat_id
SET a.blok_id = b.id

Because of the volumn of data i have, its currently timing out.由于我拥有的数据量很大,它目前超时。 is there a way around to avoid the time out without modifying db config ?有没有办法在不修改数据库配置的情况下避免超时?

The package you use does its best to allow any incomplete operation to be entirely rolled back using the host RDBMS's transaction semantics.您使用的包尽最大努力允许使用主机 RDBMS 的事务语义完全回滚任何不完整的操作。 That means it is designed to do update operations like the one you showed us in an ACID-compliant single transaction.这意味着它旨在执行更新操作,就像您在符合 ACID 的单个事务中向我们展示的那样。

If the tables involved are large (millions of rows or more) the transactions can be very large.如果涉及的表很大(数百万行或更多),则事务可能非常大。 They can make your MySQL server thrash, spilling transaction logs to disk or SSD.它们可以使您的 MySQL 服务器崩溃,将事务日志溢出到磁盘或 SSD。 Committing those transaction logs can take a very long time.提交这些事务日志可能需要很长时间。 You didn't mention row counts, but if they are large is is possible that flyway is not the right tool for this job.您没有提到行数,但如果它们很大,那么 flyway 可能不是这项工作的正确工具。

Your lock timeout hints that you are doing this operation on a database with other concurrent activity.您的锁定超时提示您正在对具有其他并发活动的数据库执行此操作。 You may want to do it on an otherwise quiet database for best results.您可能希望在其他安静的数据库上执行此操作以获得最佳结果。

You can increase the lock wait timeout by doing this.您可以通过这样做来增加锁定等待超时。

show variables like 'innodb_lock_wait_timeout'; -- previous vale
SET GLOBAL innodb_lock_wait_timeout = 300; -- five min

Then, perhaps, try again, just before sunrise on a holiday or another quiet time.然后,也许,在假期或其他安静时间日出之前再试一次。 More information here .更多信息在这里

Consider restoring the lock timeout to its previous value when your flyway job is done.当你的飞行任务完成时,考虑将锁定超时恢复到之前的值。

You can also consider doing your update in batches, for example 1000 rows at a time.您还可以考虑分批进行更新,例如一次 1000 行。 But flyway doesn't seem to support that.但flyway似乎并不支持这一点。 If you go that route you can ask another question.如果你走那条路,你可以问另一个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM