zoukankan      html  css  js  c++  java
  • How to disable index in innodb

    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

  • 相关阅读:
    各IDE快捷键
    java的GUI之SWT框架 JavaFX框架 配置开发环境(包含但不限于WindowBuilder完整教程,解决Unknown GUI toolkit报错,解决导入SWT包错误)
    20180314 一个浮点数问题
    20180309 算最近新的感悟吧
    20171228 C#值类型和引用类型
    20171129 ASP.NET中使用Skin文件
    20171123初学demo爬去网页资料
    20171018 在小程序页面去获取用户的OpenID
    20171018 微信小程序客户端数据和服务器交互
    20171012 动态爬虫爬取预约挂号有号信息
  • 原文地址:https://www.cnblogs.com/xiaotengyi/p/3604260.html
Copyright © 2011-2022 走看看