MySQL: Speed of INSERT Statements
2015-06-20 16:03
731 查看
Speed of INSERT Statements
To optimize insert speed, combine many small operations into a single large operation. Ideally, you make a single connection, send the data for many new rows at once, and delay all index updates and consistency checking until the very end.The time required for inserting a row is determined by the following factors, where the numbers indicate approximate proportions:
Connecting: (3)
Sending query to server: (2)
Parsing query: (2)
Inserting row: (1 × size of row)
Inserting indexes: (1 × number of indexes)
Closing: (1)
This does not take into consideration the initial overhead to open tables, which is done once for each concurrently running 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 are inserting many rows from the same client at the same time, use
INSERTstatements with multiple
VALUESlists to insert several rows at a time. This is considerably faster (many times faster in some cases) than using separate single-row
INSERTstatements. If you are adding data to a nonempty table, you can tune the
bulk_insert_buffer_sizevariable 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 20 times faster than using
INSERTstatements. See Section 13.2.6, “LOAD DATA INFILE Syntax”.
Take advantage of the fact that columns have default values. Insert values explicitly only when the value to be inserted differs from the default. This reduces the parsing that MySQL must do and improves the insert speed.
See Section 8.5.2, “Bulk Data Loading for MyISAM Tables” for tips specific to
MyISAMtables.
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主键约束和唯一性约束
- Mysql常用命令行
- MySQL数据库远程连接开启方法
- com.mysql.jdbc.Driver和org.gjt.mm.mysql.Driver区别
- MySQL常用命令
- 【转】【mysql的设计与优化专题】mysql的最佳索引攻略
- Windows Server 2003 下配置 MySQL 集群(Cluster)教程
- MySQL常用命令汇总
- 图书管理系统(mysql部分) 初步设…
- mysql 数据库优化(未完)
- mysql 存储过程的一个bug或者是我…
- mysql 学习总结
- mysql 索引(index)
- mysql 存储过程(procedure)
- mysql 存储引擎  和 事务
- mysql 触发器的创建、问题、解决方…
- mysql 触发器的创建、问题、解决方…
- mysql 命令行操作另外一种进入方式
- mysql 命令行操作另外一种进入方式
- mysql 字符集(CHARACTER SET)和…