时间:2021-07-01 10:21:17 帮助过:23人阅读
对一个表进行删除操作,如果这个列上没有索引,或者执行计划没有走搜索,会导致删除锁住全部的列
mysql> show indexes from city1;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| city1 | 0 | PRIMARY | 1 | ID | A | 3764 | NULL | NULL | | BTREE | | |
| city1 | 1 | idx_code | 1 | CountryCode | A | 232 | NULL | NULL | | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)
mysql> alter table city1 drop index idx_code;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql>
mysql>
mysql> select * from city1 limit 10;
+----+----------------+-------------+---------------+------------+
| ID | Name | CountryCode | District | Population |
+----+----------------+-------------+---------------+------------+
| 1 | Kabul | AFG | Kabol | 1780000 |
| 2 | Qandahar | AFG | Qandahar | 237500 |
| 3 | Herat | AFG | Herat | 186800 |
| 4 | Mazar-e-Sharif | AFG | Balkh | 127800 |
| 5 | Amsterdam | NLD | Noord-Holland | 731200 |
| 6 | Rotterdam | NLD | Zuid-Holland | 593321 |
| 7 | Haag | NLD | Zuid-Holland | 440900 |
| 8 | Utrecht | NLD | Utrecht | 234323 |
| 9 | Eindhoven | NLD | Noord-Brabant | 201843 |
| 10 | Tilburg | NLD | Noord-Brabant | 193238 |
+----+----------------+-------------+---------------+------------+
10 rows in set (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> update city1 set name=‘aaa‘ where CountryCode=‘AFG‘;
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> begin
-> ;
Query OK, 0 rows affected (0.00 sec)
mysql> delete from city1 where CountryCode=‘NLD‘;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
MySQL 多个in 条件需要注意的地方
标签:out ESS lock update aaa begin 扫描 record sub