MySQL storage engine - MyISAM and InnoDB

 

            

     The basic differences are:

The MyISAM type does not support advanced processing such as transaction processing, while the InnoDB type does.

The MyISAM type of table emphasizes performance. It performs several times faster than the InnoDB type, but does not provide transaction support, while InnoDB provides transaction support and advanced database functions such as foreign keys.

 

     Details comparison:

 

  1. MySQL uses MyISAM by default, and InnoDB is used by default after version 5.5.
  2. InnoDB's primary key range is larger, up to 2 times that of MyISAM. The maximum length of the primary key under MyISAM is 1000bytes
  3.  MyISAM does not support transactions, while InnoDB does. InnoDB's AUTOCOMMIT is enabled by default, that is, each SQL statement will be encapsulated into a transaction by default and automatically submitted, which will affect the speed, so it is best to display multiple SQL statements between begin and commit to form a transaction. to submit.
  4.  InnoDB does not support full text indexing, while MyISAM does. Full-text indexing refers to establishing an inverted index for each word (except stop words) in char, varchar and text. MyISAM's full-text index is actually useless, because it does not support Chinese word segmentation, it must be written into the data table by the user after word segmentation, and words with less than 4 Chinese characters will be ignored like stop words.
  5.  In the query statement, if it is a single-table query, then MyISAM is faster than InnoDB , but when the multi-table joint query is suitable for InnoDB , it seems to be faster than MyISAM

 

 

 

  Differences in composition:

  
  Each MyISAM is stored as three files on disk. The name of the first file begins with the name of the table, and the extension indicates the file type.

  .frm files store table definitions.

  Data files have the extension .MYD (MYData).

  Index files have the extension .MYI (MYIndex).

  
  The disk-based resources are the InnoDB tablespace data files and its log files. The size of the InnoDB table is only limited by the size of the operating system files, typically 2GB.
  
  In terms of transaction processing:

  
  The MyISAM type table emphasizes performance, and its execution is several times faster than the InnoDB type, but does not provide transaction support

  
  InnoDB provides advanced database features such as transaction support transactions, foreign keys, etc.

  
  SELECT   UPDATE,INSERT,Delete操作
  
  MyISAM is the better choice if doing a lot of SELECTs

  
  1. If your data performs a lot of INSERT or UPDATE , you should use InnoDB table for performance reasons. 2. When

  DELETE FROM table , InnoDB will not recreate the table, but delete row by row.

  3. The LOAD TABLE FROM MASTER operation does not work for InnoDB. The solution is to first change the InnoDB table to a MyISAM table, import the data and then change it to an InnoDB table, but for the additional InnoDB features (such as foreign keys) used Table does not apply

  
  Operations on AUTO_INCREMENT

  
  
  每表一个AUTO_INCREMEN列的内部处理。

  MyISAM为INSERT和UPDATE操作自动更新这一列。这使得AUTO_INCREMENT列更快(至少10%)。在序列顶的值被删除之后就不能再利用。(当AUTO_INCREMENT列被定义为多列索引的最后一列,可以出现重使用从序列顶部删除的值的情况)。

  AUTO_INCREMENT值可用ALTER TABLE或myisamch来重置

  对于AUTO_INCREMENT类型的字段,InnoDB中必须包含只有该字段的索引,但是在MyISAM表中,可以和其他字段一起建立联合索引

  更好和更快的auto_increment处理

  
  如果你为一个表指定AUTO_INCREMENT列,在数据词典里的InnoDB表句柄包含一个名为自动增长计数器的计数器,它被用在为该列赋新值。

  自动增长计数器仅被存储在主内存中,而不是存在磁盘上

  关于该计算器的算法实现,请参考

  AUTO_INCREMENT列在InnoDB里如何工作

  
  表的具体行数
  
  select count(*) from table,MyISAM只要简单的读出保存好的行数,注意的是,当count(*)语句包含   where条件时,两种表的操作是一样的

  
  InnoDB 中不保存表的具体行数,也就是说,执行select count(*) from table时,InnoDB要扫描一遍整个表来计算有多少行

  
  
  
  表锁

  
  提供行锁(locking on row level),提供与 Oracle 类型一致的不加锁读取(non-locking read in
   SELECTs),另外,InnoDB表的行锁也不是绝对的,如果在执行一个SQL语句时MySQL不能确定要扫描的范围,InnoDB表同样会锁全表,例如update table set num=1 where name like “%aaa%”

 

 

 

MyISAM的好处如下:

  1、平台上承载的大部分项目是读多写少的项目,而MyISAM的读性能是比Innodb强不少的。

  2、MyISAM的索引和数据是分开的,并且索引是有压缩的,内存使用率就对应提高了不少。能加载更多索引,而Innodb是索引和数据是紧密捆绑的,没有使用压缩从而会造成Innodb比MyISAM体积庞大不小。

  3、经常隔1,2个月就会发生应用开发人员不小心update一个表where写的范围不对,导致这个表没法正常用了,这个时候MyISAM的优越性就体现出来了,随便从当天拷贝的压缩包取出对应表的文件,随便放到一个数据库目录下,然后dump成sql再导回到主库,并把对应的binlog补上。如果是Innodb,恐怕不可能有这么快速度,别和我说让Innodb定期用导出xxx.sql机制备份,因为最小的一个数据库实例的数据量基本都是几十G大小。

  4、从接触的应用逻辑来说,select count(*) 和order by 是最频繁的,大概能占了整个sql总语句的60%以上的操作,而这种操作Innodb其实也是会锁表的,很多人以为Innodb是行级锁,那个只是where对它主键是有效,非主键的都会锁全表的。

  5、还有就是经常有很多应用部门需要我给他们定期某些表的数据,MyISAM的话很方便,只要发给他们对应那表的frm.MYD,MYI的文件,让他们自己在对应版本的数据库启动就行,而Innodb就需要导出xxx.sql了,因为光给别人文件,受字典数据文件的影响,对方是无法使用的。

  6、如果和MyISAM比insert写操作的话,Innodb还达不到MyISAM的写性能,如果是针对基于索引的update操作,虽然MyISAM可能会逊色Innodb,但是那么高并发的写,从库能否追的上也是一个问题,还不如通过多实例分库分表架构来解决。

  7、如果是用MyISAM的话,merge引擎可以大大加快应用部门的开发速度,他们只要对这个merge表做一些select count(*)操作,非常适合大项目总量约几亿的rows某一类型(如日志,调查统计)的业务表。

  当然Innodb也不是绝对不用,用事务的项目就用Innodb的。另外,可能有人会说你MyISAM无法抗太多写操作,但是可以通过架构来弥补。

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326485452&siteId=291194637