What is the difference between MyISAM and InnoDB?



the difference:

1. InnoDB supports transactions, but MyISAM does not. For InnoDB, each SQL language is encapsulated into a transaction by default and automatically committed, which will affect the speed, so it is best to put multiple SQL languages ​​between begin and commit to form a transaction;

2. InnoDB supports foreign keys, while MyISAM does not. Converting an InnoDB table with foreign keys to MYISAM will fail;

3. InnoDB is a clustered index. The data file is bound to the index. It must have a primary key. The efficiency of indexing through the primary key is very high. However, the secondary index requires two queries, first to query the primary key, and then to query the data through the primary key. Therefore, the primary key should not be too large, because if the primary key is too large, the other indexes will also be large. MyISAM is a non-clustered index, the data files are separated, and the index stores pointers to the data files. Primary key indexes and secondary indexes are independent.

4. InnoDB does not save the specific number of rows in the table, and a full table scan is required when executing select count(*) from table. MyISAM uses a variable to save the number of rows in the entire table. When executing the above statement, you only need to read the variable, which is very fast;

5. Innodb does not support full-text indexing, while MyISAM supports full-text indexing, and MyISAM has higher query efficiency;


how to choose:

1. Whether you want to support transactions, if you want, please choose innodb, if you don't need it, you can consider MyISAM;

2. If the vast majority of the tables are only read queries, you can consider MyISAM. If both read and write are frequent, please use InnoDB.

3. After the system crashes, it is more difficult for MyISAM to recover. Is it acceptable?

4. Innodb has become the default engine of MySQL since MySQL 5.5 (previously it was MyISAM), which means that its advantages are obvious to all. If you don't know what to use, then use InnoDB, at least it will not be bad.




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, generally 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 operations
   MyISAM is a better choice if doing a lot of SELECTs

1. If your data performs a lot of INSERT or UPDATE , you should use InnoDB tables 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


Internal processing of one AUTO_INCREMEN column per table.

MyISAM automatically updates this column for INSERT and UPDATE operations . This makes AUTO_INCREMENT columns faster (at least 10%). The value at the top of the sequence cannot be reused after it has been deleted. (When an AUTO_INCREMENT column is defined as the last column of a multicolumn index, reuse of values ​​removed from the top of the sequence can occur).

The AUTO_INCREMENT value can be reset with ALTER TABLE or myisamch

For fields of type AUTO_INCREMENT, InnoDB must contain an index of only this field, but in MyISAM tables, a joint index can be established with other fields

Better and faster auto_increment handling

If you specify an AUTO_INCREMENT column for a table, the InnoDB table handle in the data dictionary contains a counter called an auto-increment counter, which is used to assign new values ​​to the column.

Auto-increment counters are only stored in main memory, not on disk

For the algorithm implementation of this calculator, please refer to

How AUTO_INCREMENT columns work in InnoDB

The specific number of rows in the table
   select count(*) from table, MyISAM simply reads the number of saved rows. Note that when the count(*) statement contains the where condition, the operations of the two tables are the same

InnoDB does not save the specific number of rows in the table, that is, when executing select count(*) from table, InnoDB needs to scan the entire table to calculate how many rows there are

lock
   table lock

Provide row lock (locking on row level), provide non-locking read in
  SELECTs consistent with Oracle type, in addition, the row lock of InnoDB table is not absolute, if MySQL executes a SQL statement Unable to determine the range to be scanned, the InnoDB table will also lock the entire table, such as update table set num=1 where name like “%aaa%”



Guess you like

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