简体   繁体   English

如何索引MySQL中预先存在的数据?

[英]How do I index pre-existing data in MySQL?

I created an index on a MySQL innodb table that I imported data too . 我创建了我的进口数据 MySQL的InnoDB表的索引。 The table was created by MySQL when the table was imported. 该表是在导入表时由MySQL创建的。 I did nothing. 我什么也没做。 It simply imported the data with the GUI. 它只是使用GUI导入数据。

Then I tried to add an index: 然后我尝试添加一个索引:

ALTER TABLE my_table ADD INDEX idx_myindex (some_column);

I always get: 我总是得到:

Query OK, 0 rows affected (0.22 sec) Records: 0 Duplicates: 0 Warnings: 0 查询正常,0行受影响(0.22秒)记录:0重复:0警告:0

I read this question: 我读了这个问题:

MySql Add Index : 0 Rows Affected MySql添加索引:0受影响的行

How do I make my table that already has data in it to index the column which actually affects the row? 如何使我的表中已有数据来索引实际影响该行的列? I am using innoDB. 我正在使用innoDB。

Do I need to export, delete all data, reimport (making index update)? 我是否需要导出,删除所有数据,重新导入(进行索引更新)?

MySQL 5.1 and earlier reported N rows affected when you create an index, and N was always the number of rows in the table. MySQL 5.1及更早版本在创建索引时报告了N行受影响,而N始终是表中的行数。

Starting in MySQL 5.5.5, they stopped reporting that number, and decided that rows affected was always zero for all DDL statements. 从MySQL 5.5.5开始,他们停止报告该数字,并确定所有DDL语句的受影响行始终为零。 See http://bugs.mysql.com/bug.php?id=21818 http://bugs.mysql.com/bug.php?id=21818

Be assured that creating an index automatically populates it with values. 请放心,创建索引会自动使用值填充它。 You can verify this by running SHOW TABLE STATUS LIKE 'mytable' before and after creating the index. 您可以通过在创建索引之前和之后运行SHOW TABLE STATUS LIKE 'mytable'来验证这一点。 One of the fields shown is index_length , which increases after you add a secondary index. 显示的字段之一是index_length ,它在添加二级索引后会增加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM