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

How to disable index in innodb的更多相关文章

  1. mysqladmin processlist; show processlist/status/open tables/engine/variables/table status/columns/grants/index/privileges/innodb status/logs/warnings/////; 结果筛选

    mysqladmin showprocesslist可查看完整sql需要权限. SHOW PROCESSLIST显示哪些线程正在运行.您也可以使用mysqladmin processlist语句得到此 ...

  2. 15.6.2 Configuring the Merge Threshold for index pages[innodb]

    MERGE THRESHOLD 提供了可以合并相邻索引page的功能. 默认值是50 如果一个页中数据被删除或者更新减小,导致页中有空白部分,空白部分接近合并门槛的值,则会和相邻页合并, 但是两个pa ...

  3. MySQL · 引擎特性 · InnoDB index lock前世今生

    http://mysql.taobao.org/monthly/2015/07/05/ MySQL · 引擎特性 · InnoDB index lock前世今生 前言 InnoDB并发过程中使用两类锁 ...

  4. [MySQL Reference Manual]14 InnoDB存储引擎

    14 InnoDB存储引擎 14 InnoDB存储引擎 14.1 InnoDB说明 14.1.1 InnoDB作为默认存储引擎 14.1.1.1 存储引擎的趋势 14.1.1.2 InnoDB变成默认 ...

  5. MySQL 5.6 Reference Manual-14.4 InnoDB Configuration

    14.4 InnoDB Configuration 14.4.1 InnoDB Initialization and Startup Configuration 14.4.2 Configuring ...

  6. MySQL 5.6 Reference Manual-14.3 InnoDB Transaction Model and Locking

    14.3 InnoDB Transaction Model and Locking 14.3.1 InnoDB Lock Modes 14.3.2 InnoDB Record, Gap, and Ne ...

  7. MySQL 5.6 Reference Manual-14.2 InnoDB Concepts and Architecture

    14.2 InnoDB Concepts and Architecture 14.2.1 MySQL and the ACID Model 14.2.2 InnoDB Multi-Versioning ...

  8. Differences between INDEX, PRIMARY, UNIQUE, FULLTEXT in MySQL?

    487down vote Differences KEY or INDEX refers to a normal non-unique index.  Non-distinct values for ...

  9. InnoDB 存储引擎的锁机制

    测试环境隔离级别:REPEATABLE-READ 行级别的 - Share and Exclusive Locks 共享锁 S:允许持有S锁的事务对行进行读操作 排他锁 X: 允许持有X锁的事务对行进 ...

随机推荐

  1. zabbix使用iostat命令参数监控磁盘性能

    iostat命令 先说一个坑把,在开始监控的时候使用命令iostat -dtkx,得到的结果看上去没问题,但是在web监控窗口数据就说不变动,为啥呢,因为iostat这个命令得到的第一个数据始终是磁盘 ...

  2. mysql5.7数据库与5.7之前版本比较

    数据库初始化方式变更 <5.7 版本 mysql_install_db >5.7 版本 bin/mysqld --initialize --user =mysql --basedir=/u ...

  3. 怎么修复网站漏洞 骑士cms的漏洞修复方案

    骑士CMS是国内公司开发的一套开源人才网站系统,使用PHP语言开发以及mysql数据库的架构,2019年1月份被某安全组织检测出漏洞,目前最新版本4.2存在高危网站漏洞,通杀SQL注入漏洞,利用该网站 ...

  4. Leecode刷题之旅-C语言/python-58.最后一个单词的长度

    /* * @lc app=leetcode.cn id=58 lang=c * * [58] 最后一个单词的长度 * * https://leetcode-cn.com/problems/length ...

  5. Jupyter Notebook里面使用Matplotlib画图 图表中文乱码问题

    可查看以下链接: https://blog.csdn.net/ccblogger/article/details/79613335

  6. java 堆栈内存分析详解

    计算机术语里面堆和栈代表不同的存储结构:stack-栈:heap-堆 所以java虚拟机(JVM)中堆和栈是两种内存 堆.栈对比 对比点 堆 栈 JVM中的功能 内存数据区 内存指令区 动静态 运行时 ...

  7. JAVA大作业汇总1

    JAVA大作业 代码 ``` package thegreatwork; import javafx.application.; import javafx.scene.control.; impor ...

  8. 【算法】 string 转 int

    [算法] string 转 int 遇到的一道面试题, 当时只写了个思路, 现给出具体实现 ,算是一种比较笨的实现方式 public class StringToInt { /// <summa ...

  9. Delphi7目录结构----初学者参考

    打开Delphi的安装目录,如C:\Program Files\Borland\Delphi7,你将会看到目录下包含了一些文件和文件夹: ²        Source:存放的是Delpi提供的所有源 ...

  10. JDBC剖析篇(1):java中的Class.forName()

    一.Class.forName() 在Java中我们一般用下面这样的语句来连接数据库(以MySQL为例) Class.forName("com.mysql.jdbc.Driver" ...