MySQL engine: InnoDB or MyISAM?

MyISAM storage engine

       MyISAM is the default storage engine. It is based on the older ISAM code but has many useful extensions. Some of the features MyISAM storage engine:

      All data values ​​stored in the low byte first. This allows the operating system and the data separating unit. The only requirement for binary portability is that the machine's complement (such as the recent 20 years as some machines) and IEEE floating point format (in the main machine is completely dominant). The only machine does not support binary compatibility are embedded systems. These systems sometimes use a special processor.

        First byte of the stored data does not seriously affect the low speed; row data bytes are generally not combined, unaligned byte read from one direction is not more than consume more resources from the reverse read. Get the value of the column code on the server does not seem tight than other code.

         Large files (up to 63 file length) are supported on support for large file systems and operating systems.

         When the delete and update and insert when mixed, dynamic size rows less debris. This block is deleted by combining adjacent to, and if the next block is deleted, it is extended to the one done automatically.

         The maximum number of indexes per MyISAM table is 64. This can be changed by recompiling. The maximum number of columns per index is 16.

         The maximum key length is 1000 bytes. This can also be changed by the compiler. In the case of the key length of over 250 bytes, a more than 1024-byte blocks are key to spend.

         BLOB and TEXT columns can be indexed.

        NULL values ​​are allowed in the column index. This accounts for 0-1 bytes per key.

         All figures in the high byte is the first key are stored to allow for a higher compression indexed.

        When records sorted order row insertion (as you use of a AUTO_INCREMENT column), is split so that the high index tree comprising a node key only. This improves space utilization index tree.

         A column AUTO_INCREMEN internal processing per table. INSERT and UPDATE operations for the MyISAM automatically updates this column. This makes AUTO_INCREMENT columns faster (at least 10%). No longer be utilized after a top value sequence is deleted. (When the last one AUTO_INCREMENT column is defined as a multi-column index, the case of using a weight value is removed from the top sequence may occur). ALTER TABLE AUTO_INCREMENT value can be reset or myisamch.

         If the middle of the table data file no free block, and in the other thread read from a table at the same time, you can INSERT new rows to the table. (This is known for concurrent operation). Occurs as a result of free blocks is deleted rows or more content data than the current length of the row of dynamic updated results. When all the free blocks are exhausted (filled), and inserted into the next concurrent.

         You can put data files and index files in different directories, with DATA DIRECTORY and INDEX DIRECTORY options to CREATE TABLE higher speeds, see Section 13.1.5, "CREATE TABLE Syntax."

         Each character column can turn different character sets.

        In MyISAM index file and a flag which indicates whether the table was closed properly. If you start mysqld, MyISAM table with --myisam-recover option is checked automatically when opened too, if the table is not closed properly, they repair the table.

        If you use the --update-state option to run myisamchk, it marked the table as checked. myisamchk --fast only check those tables that do not have this logo.

        myisamchk --analyze for some key storage statistics, but also for the whole key storage statistics.

        myisampack can pack BLOB and VARCHAR columns.

MyISAM also supports the following features:

         Support true VARCHAR type; VARCHAR is stored in the column length of 2 bytes to begin.

         There VARCHAR table can be fixed or dynamic record length.

         VARCHAR and CHAR columns can be up to 64KB.

         A messing index has been calculated may be used for UNIQUE. This allows you to have UNIQUE on any merger columns in the table. (However, you can not search on a UNIQUE computed index).

InnoDB storage engine

InnoDB provides MySQL with a with a commit, rollback, and crash recovery capabilities of transaction-safe (ACID compliant) storage engine. InnoDB row-level locking SELECT statement and also provides an Oracle-style consistent non-locking read. These features increase multi-user deployment and performance. There is no need to expand locked in InnoDB, because InnoDB BOC-level locking for very small space. InnoDB also supports FOREIGN KEY mandatory. In the SQL query, you can freely type InnoDB table types with other MySQL tables mixed up, even in the same query can also be mixed.

InnoDB is designed for maximum performance processing huge amounts of data. Its CPU efficiency is probably any other disk-based relational database engine can not match.

InnoDB storage engine is fully integrated with MySQL server, InnoDB storage engine to cache data and indexes in main memory and maintains its own buffer pool. InnoDB stores its tables & indexes in a table space, table space can contain several files (or raw disk partitions). This is different from MyISAM table, such MyISAM tables each table is present in a separate file. InnoDB tables can be any size, even when the file size is limited to the operating system 2GB.

InnoDB is included by default in the MySQL binary distribution. Windows Essentials installer makes InnoDB the default table of MySQL on Windows.

InnoDB is used to generate at numerous large database sites requiring high performance. The famous Internet news site Slashdot.org runs on InnoDB. Mytrix, Inc. store more than 1TB of data on InnoDB, there are other sites treated per second 800 insertion load / update on InnoDB.

The difference between InnoDB and MyISAM

Overview difference:

MyISAM is the default MySQL storage engine, is generally not too many people care about this stuff. Decide what kind of storage engine is a very tricky thing, but still we went to look at the value of the article here MyISAM and InnoDB consider only two, because these two are the most common.

Let's start with some questions:

Your database has foreign keys do?

You need transaction support it?

You need full-text index it?

What you often use the query mode?

How much of your data?

Think about these issues above allows you to find the right direction, but it is not absolute. If you need transactions or foreign key, then InnoDB may be a better way. If you need full-text index, generally speaking MyISAM is a good choice, because it is built into the system, however, we actually do not often go to test two million rows. So, even if a little slower, we can obtain the full-text index from InnoDB by using Sphinx.

The size of the data is an important factor affecting what kind of storage engine you choose, large data sets tend to select the InnoDB way, because of its support for transaction processing and fault recovery. Database recovery in a small determined the length of time, InnoDB transaction log can be used for data recovery, it will be faster. The MyISAM may take several hours or even days to dry these things, InnoDB only a few minutes.

You used to operate a database table may also be a significant factor affecting the performance right. For example: COUNT () in MyISAM table, very fast, and can be very painful in InnoDB tables. The primary key query then would be very, very fast in InnoDB, but need to be careful of is that if our primary key too long can also cause performance problems. A large number of inserts in MyISAM statement will be faster, but updates will be faster under the InnoDB - especially when large concurrent.

So, in the end do you check which one to use? According to experience, if some small applications or projects, then the MyISAM may be more suitable. Of course, the use of MyISAM in large environment will be a great success, but it is not always the case. If you are planning to use a large amount of data items, but also to support transactions or foreign keys, then you should really direct way to use InnoDB. But keep in mind InnoDB tables require more memory and storage, 100GB of MyISAM table conversion to InnoDB tables may make you have a very bad experience.

The difference between Summary:

1.InnoDB FULLTEXT index type is not supported.

Specific number of rows of 2.InnoDB not save the table, that is, the implementation of select count (*) when from table, InnoDB again to scan the entire table to calculate how many rows, but MyISAM simply read out the saved line number It can be. Note that, when the count (*) statement contains a condition where the operation two kinds of tables is the same.

3. For AUTO_INCREMENT type of field, InnoDB must contain only the index of the field, but in the MyISAM table, you can index and other fields to establish a joint together.

When 4.DELETE FROM table, InnoDB will not re-establish the table, but delete the line by line.

5.LOAD TABLE FROM MASTER InnoDB operation does not work, the solution is first put into InnoDB tables MyISAM table, and then import the data into InnoDB tables, but for additional InnoDB characteristics (e.g., foreign key) used table does not apply.

In addition, the row lock InnoDB tables is not absolute, if MySQL can not determine the range to be scanned, InnoDB tables will also lock the whole table, in the implementation of a SQL statement such as update table set num = 1 where name like "% aaa%"

InnoDB enhance the performance of the method:

MyISAM and InnoDB storage engine performance difference is not great for InnoDB, the performance impact is mainly innodb_flush_log_at_trx_commit this option, if set, then 1, then insert each time data is automatically filed, leading to a sharp decline in performance, it should be a relationship with the refresh log, set to 0 to see efficiency improved significantly, of course, you can submit the same SQL in "sET AUTOCOMMIT = 0" is set to achieve good performance. Also, I heard that can improve performance by setting innodb_buffer_pool_size InnoDB, but I found no particular test significantly improved.

Basically we can consider using InnoDB instead of MyISAM engine of our, because a lot of InnoDB its good features, such as transaction support, stored procedures, views, row-level locking, etc., in the case of concurrent lot, I believe InnoDB's performance certainly much stronger than MyISAM, of course, the appropriate configuration in the my.cnf is relatively critical, good configuration, can effectively speed up your application.

Any kind of table is not a panacea, only the right to choose the right type of business for the table type used to play the greatest performance advantage of MySQL.

Guess you like

Origin blog.csdn.net/weixin_34205076/article/details/91012481