在MySQL中使用ALTER TABLE构建索引需要多长时间? [英] How long should it take to build an index using ALTER TABLE in MySQL?

查看:163
本文介绍了在MySQL中使用ALTER TABLE构建索引需要多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能有点像询问字符串长度是多长,但统计数据是:

This might be a bit like asking how long a length of string is, but the stats are:


  • 英特尔双核4GB内存

  • 包含800万行,约20列的表,主要是具有auto_increment主ID的varchars

  • 查询是:ALTER TABLE my_table ADD INDEX my_index (my_column);

  • my_column是varchar(200)

  • 存储是MyISAM

  • Intel dual core 4GB RAM
  • Table with 8million rows, ~ 20 columns, mostly varchars with an auto_increment primary id
  • Query is: ALTER TABLE my_table ADD INDEX my_index (my_column);
  • my_column is varchar(200)
  • Storage is MyISAM

数量级,应该是1分钟,10分钟,100分钟?

Order of magnitude, should it be 1 minute, 10 minutes, 100 minutes?

谢谢

编辑:确定花了2小时37分钟,相比之下,规格较小的机器上的0小时33分钟,基本相同的设置。我不知道为什么花了这么长时间。唯一的可能性是prod机器HD满85%,100GB免费。应该足够了,但我想这取决于如何分配可用空间。

OK it took 2 hours 37 minutes, compared to 0 hours 33 mins on a lesser spec machine, with essentially identical set ups. I've no idea why it took so much longer. The only possibility is that the prod machine HD is 85% full, with 100GB free. Should be enough, but i guess it depends on how that free space is distributed.

推荐答案

如果你只是添加单个索引,大约需要10分钟。但是,如果您的内存中没有该索引文件,则需要100分钟或更长时间。

If you are just adding the single index, it should take about 10 minutes. However, it will take 100 minutes or more if you don't have that index file in memory.

200行的800 varchar最多需要1.6GB ,但由于所有的索引开销,它将需要大约2-3 GB。但是如果大多数行少于200个字符,它将花费更少。 (您可能希望选择 sum(length(my_column))以查看需要多少空间。)

Your 200 varchar with 8 million rows will take a maximum of 1.6GB, but with all of the indexing overhead it will take about 2-3 GB. But it will take less if most of the rows are less than 200 characters. (You might want to do a select sum(length(my_column)) to see how much space is required.)

您想编辑 /etc/mysql/my.cnf 文件。使用这些设置进行游戏;

You want to edit your /etc/mysql/my.cnf file. Play with these settings;

myisam_sort_buffer_size = 100M
sort_buffer_size = 100M

祝你好运。

这篇关于在MySQL中使用ALTER TABLE构建索引需要多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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