MySQL manual version 5.0.20-mysql optimization (iv) (1) (4) _php tutorial

Source: Internet
Author: User
You can speed up the INSERT operation by executing several statements together after the lock table:


LOCK TABLES a WRITE;

INSERT into a VALUES (1,23), (2,34), (4,33);

INSERT into a VALUES (8,26), (6,29);

UNLOCK TABLES;

The benefit of this performance improvement is that the index cache is flushed to disk one time until all INSERT statements have been completed. Typically, the INSERT statement has more than a few times the overhead of having the index cache flush to disk. If you can insert multiple values in one statement at a time, the displayed lock table operation is not necessary. For transaction tables, use Begin/commit instead of LOCK TABLES to increase speed. The lock table also reduces the total time of multiple connection tests, although each individual connection increases in order to wait for the maximum waiting time for the lock. For example:


Connection 1 Does inserts

Connections 2, 3, and 4 do 1 insert

Connection 5 Does inserts

If there is no lock table, the connection 2,3,4 will be done before 1,5. If the lock table is in use, the connection 2,3,4 may be completed after 1,5, but the total time may only be 40%. MySQL INSERT, UPDATE, DELETE operations are very fast, but in a statement if there are more than 5 inserts or updates when it is best to lock to achieve better performance. If you want to do a lot of insertions at once, it's best to add LOCK TABLES and UNLOCK TABLES to Each loop (about 1000 times), so that other processes can access the data table; The insert is always slower than the LOAD data INFILE, because the implementation strategy is distinct.


To make the MyISAM table faster, the LOAD DATA

INFILE and INSERT can increase the value of the system variable key_buffer_size, see "7.5.2 Tuning Server Parameters" for details.


7.2.13 Acceleration UPDATE

The UPDATE statement is optimized just like SELECT, except that it has additional write overhead. The cost of writing depends on the number of records to update and the number of indexes. If the index does not change, there is no need to update it.

http://www.bkjia.com/PHPjc/630975.html www.bkjia.com true http://www.bkjia.com/PHPjc/630975.html techarticle Several statements can be executed together after the lock table to speed up the INSERT operation: Lock TABLES a WRITE; INSERT into a VALUES (1,23), (2,34), (4,33); INSERT into a VALUES (8,26), (6,29); UNLOCK T ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.