在网上查阅了相关资料,解释是这样的:update在mysql中的处理过程是先delete然后再insert新的记录;然后我自己做了个测试
表结构很简单,只有一个普通的id字段,没加索引
test1:
mysql> insert into testupdate select * from testupdate;
Query OK, 1048576 rows affected (10.16 sec)
Records: 1048576 Duplicates: 0 Warnings: 0mysql> update testupdate set id=0;
Query OK, 2097152 rows affected (21.31 sec)
Rows matched: 2097152 Changed: 2097152 Warnings: 0mysql> delete from testupdate where id=0;
Query OK, 2097152 rows affected (21.96 sec)按理说,delete的时间应该会小于update的,但是为什么会出现这样的结果,请解释下,-----注,在更新前,表里的记录都是id=1
表结构很简单,只有一个普通的id字段,没加索引
test1:
mysql> insert into testupdate select * from testupdate;
Query OK, 1048576 rows affected (10.16 sec)
Records: 1048576 Duplicates: 0 Warnings: 0mysql> update testupdate set id=0;
Query OK, 2097152 rows affected (21.31 sec)
Rows matched: 2097152 Changed: 2097152 Warnings: 0mysql> delete from testupdate where id=0;
Query OK, 2097152 rows affected (21.96 sec)按理说,delete的时间应该会小于update的,但是为什么会出现这样的结果,请解释下,-----注,在更新前,表里的记录都是id=1
解决方案 »
- 求REPLACE写法?
- postgresql 通配符转译问题
- MYSQL如果实现存储过程加密
- 论坛数据库怎么设计好?
- 新手提问 !!!!!!!!!!!!!!!!!!!!!!
- 高手指点,在Sql server用Union(all)可以,而在Mysql怎么不行了,如果在Mysql联合查询,用什么查询语句好了??
- ADO 能否用来连接 Linux 上的MySQL数据库
- mysql -h remotehost -u root连不上对方机子?
- 在RedHat Linux7.0下配置Apache+PHP+MySQL 的问题,请提供方法或思路
- 怎么高效的删除一条数据?
- 罪过罪过,今天经过实际操作才知道内存表和临时表速度差这么多.
- mysql配置的apply security setting不成功,提示1045错误
+----------+
| count(*) |
+----------+
| 10485760 |
+----------+
1 row in set (0.06 sec)mysql> update testupdate set id=0;
Query OK, 10485760 rows affected (38.28 sec)
Rows matched: 10485760 Changed: 10485760 Warnings: 0mysql> delete from testupdate;
Query OK, 10485760 rows affected (0.67 sec)mysql>
谢谢回复,我参照 wwwwA的提示,给update也加上了条件,测试结果如下mysql> update testupdate set id=0 where id=1;
Query OK, 2097152 rows affected (21.59 sec)
Rows matched: 2097152 Changed: 2097152 Warnings: 0mysql> delete from testupdate where id=0;
Query OK, 2097152 rows affected (20.14 sec)-----------------------------------
为什么你上面的测试结果会有这么大的差距,难道就是加了where条件吗?
mysql> update testupdate set id=0 where id=1;
Query OK, 2097152 rows affected (21.59 sec)
Rows matched: 2097152 Changed: 2097152 Warnings: 0mysql> delete from testupdate where id=0;
Query OK, 2097152 rows affected (20.14 sec)
----------------------------------------------------
貌似差异很小,
"在网上查阅了相关资料,解释是这样的:update在mysql中的处理过程是先delete然后再insert新的记录;"?另外,你用的是什么存储引擎?
你好,我的引擎是innodb,这个结论我在某个数据库论坛看到的,我也是无从考证,所以自己做测试来验证,