MySQL storage engine performance comparison options

Original address of learning:

https://blog.csdn.net/qushaming/article/details/82773783

About the characteristics and choices of MySQL storage engines

The basic idea is that the MyISAM engine is more suitable for simple insert and select systems. If the system does not update and delete very frequently, you can consider using this storage engine.

However, if the data consistency transaction requirements are relatively high and there are more update requirements, InnoDB is recommended.

Quoting the original conclusion suggestion:

MyISAM: If the application is based on read operations and insert operations, with few update and delete operations, and the integrity and concurrency requirements of the transaction are not very high, then this storage engine is very suitable. MyISAM is one of the most commonly used storage engines in the Web, data warehouse and other application environments.

InnoDB: Used for transaction processing applications and supports foreign keys. If the application has relatively high requirements for transaction integrity, and requires data consistency under concurrent conditions, data operations include many update and delete operations in addition to inserts and queries, then the InnoDB storage engine is a more appropriate choice . InnoDB storage engine not only effectively reduces locks due to deletions and updates, but also ensures complete commit and rollback of transactions. For systems like billing systems or financial systems that require high data accuracy, InnoDB is a suitable choice.

MEMORY: Store all data in RAM, and provide extremely fast access in environments where fast location records and other similar data are required. The defect of MEMORY is that there is a limit to the size of the table. Tables that are too large cannot be cached in memory. Second, it is necessary to ensure that the data of the table can be restored. The data in the table can be restored after the abnormal termination of the database. The MEMORY table is usually used to update small tables that are not frequently updated to quickly access the results.

MERGE: Used to logically combine a series of equivalent MyISAM tables and refer to them as an object. The advantage of the MERGE table is that it can break through the limitation on the size of a single MyISAM table, and by distributing different tables on multiple disks The above can effectively improve the access efficiency of MERGE tables, which is very suitable for VLDB environments such as data warehouses.

How to specify the storage engine

The storage engine has default settings when installing the database, but you can also specify different storage engines for separate tables.

Specify the storage engine of the data table, the demo table is as follows, pay attention to the middle keyword: ENGINE = MyISAM:


SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for epa_monit_alarm_data_myisam
-- ----------------------------
DROP TABLE IF EXISTS `epa_monit_alarm_data_myisam`;
CREATE TABLE `epa_monit_alarm_data_myisam`  (
  `id` bigint(0) NOT NULL AUTO_INCREMENT COMMENT '唯一`yanru_test`主键',
  `alarm_status` int(0) NULL DEFAULT NULL COMMENT '是否报警,为1表示报警,为0表示解除报警',LT NULL COMMENT '压力/真空阀状态(0、1、2、N)',
  `critical_pressure_state` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '压力/真空阀临界压力状态(0、1、2、N)',
  `post_processing_device_status` varchar(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '后处理装置状态(0、1、2、N)',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `ids_alarm_status`(`alarm_status`) USING BTREE,
  INDEX `ids_enterprise_code`(`enterprise_code`) USING BTREE,
  INDEX `ids_tanker_id`(`tanker_id`) USING BTREE,
  INDEX `ids_date`(`date`) USING BTREE
) ENGINE = MyISAM AUTO_INCREMENT = 642 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '采集加油站数据:加油站相关的报警预警数据' ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

Comparison test of storage engine insertion speed

For the two storage engines MyISAM and InnoDB, I did some performance tests respectively.

Taking the insertion of 1000 pieces of data as an example, MyISAM takes 96% of InnoDB's time.

MyISAM table execution time-consuming InnoDB table execution time-consuming
117.117s 122.289s

Inserting 100,000 pieces of data as an example, MyISAM takes up 99% of InnoDB's time.

MyISAM table execution time-consuming InnoDB table execution time-consuming
12078.579s 12179.141s

Calculate it and compare it with instantaneous sampling,

Comprehensive comparison, you will find that, in fact, the overall insertion efficiency using MyISAM is not much faster than InnoDB! So the choice of these two storage engines does not depend on the demand for data insertion speed!

Guess you like

Origin blog.csdn.net/Stephanie_1/article/details/105443897