如果列重命名,MySQL是否会重建列的索引?

时间:2011-04-04 23:15:13

标签: mysql indexing

列名是唯一正在改变的东西...... MySQL会重建那个索引吗?

2 个答案:

答案 0 :(得分:1)

对于C-ISAM不会这么认为,对INNODB不确定。你尝试的时候会发生什么?

答案 1 :(得分:1)

create table t1(id int, name varchar(100));
alter table t11 add index name_idx(name);

mysql> show create table t11;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                           |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
| t11   | CREATE TABLE `t11` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  KEY `name_idx` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


alter table t11 change column name  name1 varchar(100);

mysql> show create table t11;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                             |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| t11   | CREATE TABLE `t11` (
  `id` int(11) DEFAULT NULL,
  `name1` varchar(100) DEFAULT NULL,
  KEY `name_idx` (`name1`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql会自动更改u的索引 并且不重建索引