Mysql:speed of INSERT statements

Source: Internet
Author: User

Speed of INSERT statements

To optimize insert speed, combine many small operations into a single large operation. Ideally, connection, send the data for many new rows at once, and delay all index updates and Consistenc Y checking until the very end.

The time required for inserting a row was determined by the following factors, where the numbers indicate approximate Propo Rtions:

    • Connecting: (3)

    • Sending query to server: (2)

    • Parsing query: (2)

    • Inserting row: (1xsize of Row)

    • Inserting indexes: (1xnumber of indexes)

    • Closing: (1)

This does don't take into consideration the initial overhead to open tables, which are done once for each concurrently runnin G Query.

The size of the table slows down the insertion of indexes by log N , assuming b-tree indexes.

You can use the following methods to speed up inserts:

  • If you is inserting many rows from the same client at the same time, use INSERT statements with multiple VALUES lists SERT several rows at a time. This was considerably faster (many times faster in some cases) than using separate Single-row statements INSERT . If you is adding data to a nonempty table, you can tune the bulk_insert_buffer_size variable to make data insertion even faster. See section 5.1.4, "Server System Variables".

  • When loading a table from a text file, use LOAD DATA INFILE . This is usually faster than using INSERT statements. See section 13.2.6, "LOAD DATA INFILE Syntax".

  • Take advantage of the fact, columns has default values. Insert values explicitly only if the value to is inserted differs from the default. This reduces the parsing, MySQL must do and improves the insert speed.

  • See section 8.5.2, ' Bulk Data Loading for MyISAM Tables ' for tips specific to MyISAM Tables.

REF:

Http://dev.mysql.com/doc/refman/5.0/en/insert-speed.html

Http://dev.mysql.com/doc/refman/5.0/en/update-speed.html

Mysql:speed of INSERT statements

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.