Home > Backend Development > PHP Tutorial > 像这样的sql语句,mysql编译几次

像这样的sql语句,mysql编译几次

WBOY
Release: 2016-06-06 20:06:46
Original
1077 people have browsed it

insert into table values (null,'abc','123@qq.com');
insert into table values (null,'abc','123@qq.com');
insert into table values (null,'abc','123@qq.com');
这样执行3次,在mysql中编译3次

那这样的语句
insert into table values
(null,'abc','123@qq.com'),
(null,'abc','123@qq.com'),
(null,'abc','123@qq.com');
在mysql中编译几次?1次还是3次

回复内容:

insert into table values (null,'abc','123@qq.com');
insert into table values (null,'abc','123@qq.com');
insert into table values (null,'abc','123@qq.com');
这样执行3次,在mysql中编译3次

那这样的语句
insert into table values
(null,'abc','123@qq.com'),
(null,'abc','123@qq.com'),
(null,'abc','123@qq.com');
在mysql中编译几次?1次还是3次

内核没研究那么透,所以两者的具体的执行原理不是特别清楚

但是非常肯定的是批量插入效率高,SQL解析是按语句来的,所以你第一个例子是解析3条SQL语句,第二个例子是解析1条SQL语句

从IO消耗上来讲,每个SQL语句都要写一次binlog,所以批量insert只要写入一次,如果insert多的情况,性能差别会更大

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template