InnoDB引擎,从大表中删除多行

官方建议:

  • InnoDB Tables

  • If you are deleting many rows from a large table, you may exceed the lock table size for an InnoDB table. To avoid this problem, or simply to minimize the time that the table remains locked, the following strategy (which does not use DELETE at all) might be helpful:

-- 1.Select the rows not to be deleted into an empty table that has the same structure as the original table:

INSERT INTO t_copy SELECT * FROM t WHERE ... ;

-- 2.Use RENAME TABLE to atomically move the original table out of the way and rename the copy to the original name:

RENAME TABLE t TO t_old, t_copy TO t;

-- 3.Drop the original table:

DROP TABLE t_old;

大概意思:

你要detele大表中的多行,则可能导致锁定的表的数据量太多,innodb_buffer_pool没有足够空间来执行。为了避免这个问题,或者为了最小化减少持有表锁的时间,你还不如创建一张同样结构的表,把不删除的数据放里面,然后重命名原始表,并给新表命名为原始表的原始表名,这样还快一点

mysql会报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size",InnoDB引擎会因需要锁的行太多而抛出这个错误。解决就加大innodb_buffer_pool_size

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值