How to check if enable/disable keys work?

China☆狼群 提交于 2019-11-29 16:13:42

问题


I have a table with an indexed varchar(256) column.

For faster bulk insert, I disabled keys, insert more than 10 million entries, and then re-enable the keys after insertion is done.

Surprisingly, the enable/disable keys took no time:

mysql> alter table xxx disable keys;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> alter table xxx enable keys;
Query OK, 0 rows affected, 1 warning (0.00 sec)

How do I ensure that enable/disable keys were working properly?


回答1:


As you guessed, InnoDB does not support DISABLE/ENABLE KEYS. The warning you got is:

code 1031 - Table storage engine for 'table_name' doesn't have this option

As you can see here. To see the warning yourself, run SHOW WARNINGS; after you run the ALTER.




回答2:


To check if your keys are enabled/disabled, run:

show keys in table_name
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+----------+---------------+
| Table    | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment  | Index_comment |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+----------+---------------+
| table123 |          0 | PRIMARY  |            1 | id          | A         |           0 |     NULL | NULL   |      | BTREE      |          |               |
| table123 |          1 | id       |            1 | id          | A         |        NULL |     NULL | NULL   |      | BTREE      | disabled |               |
+----------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+----------+---------------+

If the key is disabled, the Comment column will show disabled. If it's enabled, the column will be empty:

[Comment column shows] information about the index not described in its own column, such as disabled if the index is disabled. ➫➫➫



来源:https://stackoverflow.com/questions/4980917/how-to-check-if-enable-disable-keys-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!