Q:

I read from many places that disabling index before loading a data table can significantly speed up the importing process. But innodb does not support "disable index". Particularly, I got a warning message after running

ALTERTABLE mytable DISABLE KEYS;
+-------+------+-------------------------------------------------------------+
| Level | Code | Message |
+-------+------+-------------------------------------------------------------+
| Note | 1031 | Table storage engine for 'mytable' doesn't have this option |
+-------+------+-------------------------------------------------------------+
1 row in set (0.00 sec)

How do I disable index in the innodb engine? Or are there any other alternatives to avoid using index when loading data from an outfile?

A:

There is a very good reason why you cannot execute DISABLE KEYS on an InnoDB. InnoDB is not designed it use it. MyISAM is.

In fact, here is what happens when you reload a mysqldump:

You will see a CREATE TABLE for a MyISAM table following by a write lock.

Before all the bulk inserts are run, a call to ALTER TABLE ... DISABLE KEYS is done.

What this does is turn off secondary indexes in the MyISAM table.

Then, bulk inserts are done. While this is being done, the PRIMARY KEY and all UNIQUE KEYS in the MyISAM table. Before the UNLOCK TABLEs, a call ALTER TABLE ... ENABLE KEYS is done in order to rebuild all nonunique indexes linearly.

IMHO this operation was not coded into the InnoDB Storage Engine because all keys in a nonunique index come with the primary key entry from gen_clust_index (aka Clustered Index). That would be a very expensive operation since building a nonunique index would require O(n log n) running time to retrieve each unique key to attach to a nonunique key.

In light of this, posting a warning about trying to DISABLE KEYS/ENABLE KEYS on an InnoDB table is far easier than coding exceptions to the mysqldump for any special cases involving non-MyISAM storage engines.

参考:

http://stackoverflow.com/questions/9524938/how-to-disable-index-in-innodb/9525780#9525780

最新文章

  1. java 如何在pdf中生成表格
  2. 使用WinSetupFromUSB来U盘安装WINDOWS2003
  3. UVa 11584 Partitioning by Palindromes【DP】
  4. [OFBiz]开发 五
  5. 防抖(Debouncing)和节流(Throttling)
  6. gcc代码反汇编查看内存分布[1]: gcc
  7. guozhongCrawler的是一个无须配置、便于二次开发
  8. python 闭包初识
  9. 对struts2一些理解
  10. Web框架本质及第一个Django实例 Web框架
  11. BZOJ5093 图的价值(NTT+斯特林数)
  12. stingray中使用angularjs
  13. 求约束------------------------ do while循环 算法思想
  14. win32多线程程序设计
  15. Linux链接脚本学习--lds(转)
  16. 在linux,arm上的屏幕搜索wifi并连接(qt,多选择,wifi按信号排列)转
  17. Qt 利用XML文档,写一个程序集合 三
  18. Java集合(4)一 红黑树、TreeMap与TreeSet(下)
  19. ubuntu 安装 consul
  20. P3393 逃离僵尸岛

热门文章

  1. go web cookie和session
  2. Eclipse_安装SAP_HANA数据库插件
  3. WPF ItemsControl 手动刷新
  4. c# string.format和tostring()
  5. 【Keras案例学习】 sklearn包装器使用示范(mnist_sklearn_wrapper)
  6. model的index无限次数执行导致stackOverFlow
  7. js鼠标事件相关知识
  8. 「日常训练」 Mike and Frog (CFR305D2C)
  9. 「题目代码」P1034~P1038(Java)
  10. Jmeter使用时异常问题解决