
MyISAM and InnoDB Explain InnoDB and MyISAM It's used by a lot of people MySQL , the two most commonly used table types , Each of these table types has its advantages and disadvantages , It depends on the application . The basic difference is :MyISAM Types do not support advanced processing such as transaction processing , and InnoDB Type of support .MyISAM Type tables emphasize performance , The ratio of execution InnoDB The type is faster .
MyISAM and InnoDB Explain
InnoDB and MyISAM It's used by a lot of people MySQL , the two most commonly used table types , Each of these table types has its advantages and disadvantages , It depends on the application . The basic difference is :MyISAM Types do not support advanced processing such as transaction processing , and InnoDB Type of support .MyISAM Type tables emphasize performance , The ratio of execution InnoDB The type is faster , Transaction support is not provided , and InnoDB Provides advanced database functions such as transaction support and external keys .
Here are some details and implementation differences :
◆1.InnoDB I won't support it FULLTEXT Index of type .
◆2.InnoDB The specific number of rows of the table is not saved in , in other words , perform select count(
) from table when ,InnoDB Scan the entire table to see how many rows there are , however MyISAM Simply read out the number of saved lines . Pay attention to is , When count(
) The statement contains where When the conditions , The operation of the two kinds of tables is the same .
◆3. about AUTO_INCREMENT Type field ,InnoDB Must contain only the index of this field , But in MyISAM In the table , You can create a union index with other fields .
◆4.DELETE FROM table when ,InnoDB The table will not be recreated , It's line by line deletion .
◆5.LOAD TABLE FROM MASTER Operation of InnoDB It doesn't work , The solution is to put InnoDB Change the watch to MyISAM surface , Import the data and change it to InnoDB surface , But for the extra InnoDB characteristic ( For example, foreign key ) The table of does not apply .
in addition ,InnoDB The row lock of the table is not absolute either , If you are executing a SQL When the sentence is MySQL Can't determine the range to scan ,InnoDB The watch also locks the whole watch , for example update table set num=1 where name like “%aaa%”
The main difference between the two types is Innodb Support transaction processing and foreign key and row level lock . and MyISAM I won't support it . therefore MyISAM It's easy to think that it's only suitable for small projects .
I use as MySQL From the user's point of view ,Innodb and MyISAM They are all favorite , However, the database platform I currently operate and maintain should meet the requirements :99.9% The stability of , For easy scalability and high availability ,MyISAM Definitely my first choice .
Here's why :
1、 First of all, most of the projects I currently carry on the platform are those that read more and write less , and MyISAM The reading performance is better than Innodb A lot better .
2、MyISAM The index and data of are separated , And the index is compressed , The memory usage rate is correspondingly increased . Can load more indexes , and Innodb It's that indexes and data are tightly bound , No compression is used, resulting in Innodb Than MyISAM It's huge .
3、 From a platform perspective , Regular septum 1,2 It will happen in a month that application developers are not careful update A table where The scope of writing is wrong , As a result, this watch can't work properly , This is the time MyISAM The superiority of the system is reflected in , Randomly take out the file of the corresponding table from the compressed package copied on the same day , Just put it in a database directory , then dump become sql Then import back to the main library , And put the corresponding binlog Fill up . If it is Innodb, I'm afraid it can't be so fast , Don't tell me to let Innodb Export regularly with xxx.sql Mechanism backup , Because the data volume of the smallest database instance on my platform is basically dozens G size .
4、 From the application logic I came into contact with ,select count(*) and order by Is the most frequent , Probably take up the whole sql Total statement 60% The above operations , And this operation Innodb In fact, I can lock my watch , Many people think Innodb It's a line lock , That's just where The primary key is valid for it , The non primary key will lock the whole table .
5、 In addition, there are often many application departments that need me to regularly provide them with some table data ,MyISAM It's very convenient , Just send them the corresponding watch frm.MYD,MYI The file of , Let them start in the corresponding version of the database , and Innodb You need to export xxx.sql 了 , Because it's just giving people documents , Affected by dictionary data files , You can't use it .
6、 If and MyISAM Than insert Write the words of operation ,Innodb Not yet MyISAM Write performance , If it's for index based update operation , although MyISAM It could be worse Innodb, But writing with high concurrency , It's also a question of whether we can catch up from the library , It's better to solve this problem by multi instance database and table structure .
7、 If it is to use MyISAM Words ,merge The engine can greatly accelerate the development speed of the application department , They just have to do this merge Watch some select count(*) operation , It is very suitable for large projects with a total amount of several hundred million rows A certain type ( Like a journal , Survey statistics ) Business table of .
Of course Innodb Not absolutely , Projects that use transactions, such as simulated stock speculation projects , I just use Innodb Of , Active users 20 When , It's easy to deal with , So I personally like Innodb Of , Only if we start from the application of database platform , I would still prefer MyISAM.
in addition , Someone might say you MyISAM Unable to resist too many write operations , But I can make up for it through architecture , Let's talk about the database platform capacity I have now : The total amount of master-slave data is several hundred T above , More than one billion a day pv The dynamic page of , There are also several large projects that call through the data interface, which are not included in pv total ,( It includes a big project because the initial stage memcached Not deployed , This causes a single database to process every day 9 Thousands of inquiries ). The average load of my overall database server is 0.5-1 about .
原网站版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230040478012.html