在MySQL中同时添加多个索引 [英] Adding multiple indexes at same time in MySQL

查看:2109
本文介绍了在MySQL中同时添加多个索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL测试期间,我想将多个索引添加到一个行超过5000万的表中。 MySQL是否支持同时为不同的列添加2个索引?如果是,我是否需要打开2个会话,或者可以通过一个命令完成?

During tests on MySQL, I wanted to add multiple indexes to a table with more than 50 million rows. Does MySQL support adding 2 indexes at the same time for different columns? If yes, Do I need to open 2 sessions or it can be done from one command?

推荐答案

是的。但是......

Yes. But...

在旧版本中,使用

ALTER TABLE tbl
    ADD INDEX(...),
    ADD INDEX(...);

这样它就可以一次性完成所有工作。

so that it will do all the work in one pass.

在较新的版本中, ALGORITHM = INPLACE 使得可以在InnoDB表的后台中完成工作,从而减少对其他表的影响处理。但是,要获得 INPLACE 处理,您可能需要单独添加每个索引。

In newer versions, ALGORITHM=INPLACE makes it so that the work can be done in the "background" for InnoDB tables, thereby having less impact on other processing. However, to get the INPLACE processing, you may need to add the each index separately.

参考手册列出了一些警告,例如处理 PRIMARY KEY

The Ref manual lists some caveats, such as dealing with PRIMARY KEY.

这篇关于在MySQL中同时添加多个索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆