MYisam表,加载数据。书上有资料说可以用
alter table tbname disable kes;
加载数据;
alter table tbname enable keys;
可以提高加载速度。
上面的keys都不是普通索引,不是primary key 和unique key。表数据1000W,在有索引的时候,我load 10W条数据,耗时 5s,
按照上面的方法:
加载进去只消耗了0.38s,但是在enable keys的时候花了7分钟,问:这种方法提高了效率,为什么整个过程时间花的更久?在enable的时候查看到的线程状态是:Repair with keycache。用这方法加载数据得到一个无碎片,紧凑的索引,而直接在有索引的表中load data的话,是不是索引会出现碎片?要是真出现索引碎片的话,我用optimize table也只需要30秒,根本不会超过1分钟。所以我觉得虽然disable kyes 可以提高索引,但是开启索引的话,消耗大时间不能忍受。。大家都采用什么方法来提高load data 呢?
alter table tbname disable kes;
加载数据;
alter table tbname enable keys;
可以提高加载速度。
上面的keys都不是普通索引,不是primary key 和unique key。表数据1000W,在有索引的时候,我load 10W条数据,耗时 5s,
按照上面的方法:
加载进去只消耗了0.38s,但是在enable keys的时候花了7分钟,问:这种方法提高了效率,为什么整个过程时间花的更久?在enable的时候查看到的线程状态是:Repair with keycache。用这方法加载数据得到一个无碎片,紧凑的索引,而直接在有索引的表中load data的话,是不是索引会出现碎片?要是真出现索引碎片的话,我用optimize table也只需要30秒,根本不会超过1分钟。所以我觉得虽然disable kyes 可以提高索引,但是开启索引的话,消耗大时间不能忍受。。大家都采用什么方法来提高load data 呢?
你的enable 7分钟 貌似不太对劲
http://forums.mysql.com/read.php?21,68820,68939#msg-68939
When you enable keys, it will have to rebuilt the whole index including the existing records, not just the newly inserted records, since it does not know which records are newly inserted.Maybe you should increase the bulk_insert_buffer_size不知道是否正确。
你前面用的是覆盖索引,里面有包含唯一性索引么??
1:INSERT DELAYED ,这个插入不需要等待MYSQL处理,直接进入系统缓存队列
2:加大bulk_insert_buffer_size值
MyISAM uses a special tree-like cache to make bulk inserts faster for INSERT ... SELECT, INSERT ... VALUES (...), (...), ..., and LOAD DATA INFILE when adding data to nonempty tables. This variable limits the size of the cache tree in bytes per thread. Setting it to 0 disables this optimization. The default value is 8MB.
第2个参数,我加了一点,但是如何知道加大这个值合适不合适呢?
第1个参数,加不上,我数据导入直接用load data的
如果在ENABLE KEY的过程中宕机了,MYISAM的索引文件很可能被损坏掉,你得再修复。可以说说你们为什么不用INNODB么?
测试一下不用load data,直接insert delayed,看看哪个快。
不过insert delayed可能会发生丢数据的情况。