数据库中利用limit批量删除数据的操作教程
程序员文章站
2022-06-17 21:18:39
执行计划:
mysql> explain delete from drp_pftzd where id in (select id from drp_pftzdbak) limit 1...
执行计划:
mysql> explain delete from drp_pftzd where id in (select id from drp_pftzdbak) limit 1000\g *************************** 1. row *************************** id: 1 select_type: delete table: drp_pftzd partitions: null type: all possible_keys: null key: null key_len: null ref: null rows: 246100 filtered: 100.00 extra: using where *************************** 2. row *************************** id: 2 select_type: dependent subquery table: drp_pftzdbak partitions: null type: unique_subquery possible_keys: primary key: primary key_len: 4 ref: func rows: 1 filtered: 100.00 extra: using index 2 rows in set (0.00 sec) mysql> explain delete from drp_pftzd where id in (select id from drp_pftzdbak) and id>10000 and id<20000 limit 1000\g *************************** 1. row *************************** id: 1 select_type: delete table: drp_pftzd partitions: null type: range possible_keys: primary key: primary key_len: 4 ref: const rows: 24310 filtered: 100.00 extra: using where *************************** 2. row *************************** id: 2 select_type: dependent subquery table: drp_pftzdbak partitions: null type: unique_subquery possible_keys: primary key: primary key_len: 4 ref: func rows: 1 filtered: 100.00 extra: using index 2 rows in set (0.00 sec)
不分批和分批的时间对比:
mysql> delete from drp_pftzd where id in (select id from drp_pftzdbak) and id>10000 and id<20000 ; query ok, 9940 rows affected (1.05 sec) mysql> rollback; query ok, 0 rows affected (0.42 sec) mysql> delete from drp_pftzd where id in (select id from drp_pftzdbak) and id>10000 and id<20000 limit 5000; query ok, 5000 rows affected (0.26 sec) mysql> delete from drp_pftzd where id in (select id from drp_pftzdbak) and id>10000 and id<20000 limit 5000; query ok, 4940 rows affected (0.25 sec)
推荐阅读
-
JSP中的PreparedStatement对象操作数据库的使用教程
-
python中连接三大主流数据库mysql,mongodb和redis的操作教程
-
PHP中MongoDB数据库的连接、添加、修改、查询、删除等操作实例
-
Oracle数据库中的级联查询、级联删除、级联更新操作教程
-
Oracle数据库使用replace函数批量删除数据中的双引号
-
数据库中利用limit批量删除数据的操作教程
-
asp中利用数组实现数据库记录的批量录入方法
-
php批量删除数据库下指定前缀的表以prefix_为例,批量删除prefix_PHP教程
-
PHP 在5.1.* 和5.2.*之间 PDO数据库操作中的不同之处小结_PHP教程
-
PHP中操作MySQL数据库的一些要注意的问题_PHP教程