Home >Backend Development >PHP Tutorial >MySQL Manual Version 5.0.20-MySQL Optimization (4) (1) (3)_PHP Tutorial

MySQL Manual Version 5.0.20-MySQL Optimization (4) (1) (3)_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:03:231001browse



7.2.12 Accelerate INSERT


The time it takes to insert a record is determined by the following factors, and the following numbers roughly represent Proportion of impact:


Connection: (3)


Send query to server: (2)


Parse query: (2)


Insert record: (1 x record size)


Insert index: (1 x number of indexes )


Close: (1)


The cost of opening the data table during initialization is not considered here, because each time the query is run, it will only do This time.


If it is a B-tree index, as the number of indexes increases, the speed of inserting records decreases at a rate of log N.


You can use the following methods to increase the insertion speed:


If you want to insert many records at the same time on the same client, You can use an INSERT statement with multiple VALUES values. This approach is much faster than using a single-value INSERT statement (faster in some cases). If you are adding records to a non-empty data table, you can adjust the value of the variable bulk_insert_buffer_size to make it faster. See "5.2.3 Server System Variables" for details.


If you want to insert a large number of records from different clients, using the INSERT DELAYED statement can also improve speed. See "14.1.4 INSERT Syntax" for details.


For MyISAM, records can be inserted while the SELECT statement is running, as long as records are not being deleted at this time.


To load a text file into a data table, use LOAD DATA INFILE. This is typically 20 times more expensive than using a large number of INSERT statements. See "14.1.5 LOAD DATA INFILE Syntax" for details.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630976.htmlTechArticle7.2.12 Accelerate INSERT The time it takes to insert a record is determined by the following factors. The following numbers roughly indicate the impact. Ratio of: Connection: (3) Send query to server: (2)...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn