如何检查启用/禁用键是否有效?

发布于 2024-10-17 12:27:22 字数 360 浏览 5 评论 0原文

我有一个带有索引 varchar(256) 列的表。

为了更快地进行批量插入,我禁用了键,插入超过 1000 万个条目,然后在插入完成后重新启用键。

令人惊讶的是,启用/禁用键不需要时间

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)

如何确保启用/禁用键正常工作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

春庭雪 2024-10-24 12:27:23

要检查您的按键是否已启用/禁用,请运行:

show keys in table_name

<前><代码>+----------+------------+------------+-------- ------+-------------+------------+----------------+--- -------+--------+------+------------+------------+-- -------------+
|表|非唯一 |键名 |索引中的序列 |列名 |整理|基数|子部分 |包装 |空|索引类型 |评论 |索引_评论 |
+----------+------------+----------+---------------- +-------------+------------+-------------+--------- -+--------+------+------------+------------+-------- --------+
|表123 | 0 |小学 | 1 |编号 |一个 | 0 |空 |空 | | BTREE | | |
|表123 | 1 |编号 | 1 |编号 |一个 |空 |空 |空 | | BTREE |已禁用 | |
+----------+------------+----------+---------------- +-------------+------------+-------------+--------- -+--------+------+------------+------------+-------- --------+

如果该键被禁用,Comment 列将显示disabled。如果启用,该列将为空:

[Comment 列显示]有关未在其自己的列中描述的索引的信息,例如,如果索引已禁用,则为 disabled➫➫➫

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. ➫➫➫

凉月流沐 2024-10-24 12:27:23

正如您所猜测的,InnoDB 不支持 DISABLE/ENABLE KEYS。您收到的警告是:

代码 1031 - 表存储引擎
“table_name”没有此选项

,正如您在此处看到的那样。
要亲自查看警告,请在运行 ALTER 后运行 SHOW WARNINGS;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文