本文介绍了从大表中删除大量记录的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从MySql DB中的大表(〜500K记录)中删除大量记录(〜200K).
I want to delete a large amount of records (~200K) from a large table (~500K records) in my MySql DB.
我想使此调用尽可能高效,因为我不希望DB在执行调用时变得无响应".我需要删除早于" 10天的记录(根据created_at
列),当前我使用的是
I want to make this call as efficient as possible because i dont want the DB to become "unresponsive" while executing the call.I need to delete records that are "older" than 10 days (according to created_at
column), currently I use:
delete from table_name where created_at < DATE_SUB(CURDATE(),INTERVAL 10 DAY)
如果有帮助,该表还具有主键id
.
The table also have a primary key id
if it helps.
有什么想法吗?
推荐答案
您有WHERE条件,请在created_at字段上添加索引.
You have a WHERE condition, add an index on created_at field.
这篇关于从大表中删除大量记录的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!