为什么MySQL使用临时表来删除主键?

时间:2021-10-14 08:44:31

When using the command:

使用命令时:

  ALTER TABLE my_table DROP PRIMARY KEY;

The state (when SHOW PROCESSLIST) appears as:

状态(当SHOW PROCESSLIST时)显示为:

  copy to tmp table

Why would it need to use a tmp table to "drop" a primary key constraint?

为什么需要使用tmp表来“删除”主键约束?

1 个解决方案

#1


5  

Consider the case of a composite primary key. In this case, the DB engine has to create a new clustered index from a synthetic key, which will require moving rows around. (Keep in mind that rows are physically ordered on disk by the primary key.) Given the rarity of this situation, it's not really worth handling the special case where your primary key is already an integer.

考虑复合主键的情况。在这种情况下,数据库引擎必须从合成密钥创建一个新的聚簇索引,这需要移动行。 (请记住,行按主键在磁盘上进行物理排序。)鉴于这种情况很罕见,处理主键已经是整数的特殊情况并不值得。

#1


5  

Consider the case of a composite primary key. In this case, the DB engine has to create a new clustered index from a synthetic key, which will require moving rows around. (Keep in mind that rows are physically ordered on disk by the primary key.) Given the rarity of this situation, it's not really worth handling the special case where your primary key is already an integer.

考虑复合主键的情况。在这种情况下,数据库引擎必须从合成密钥创建一个新的聚簇索引,这需要移动行。 (请记住,行按主键在磁盘上进行物理排序。)鉴于这种情况很罕见,处理主键已经是整数的特殊情况并不值得。