mysql插入多条数据时间复杂度比较

2018-06-17 23:15:59来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

  • SQL脚本

select * from users;

  • 方式一:

insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");
insert into users(name, age, course_id) VALUES("test",1, "0");

  • 方式二:

insert into users(name, age, course_id) VALUES("test",1, "0"),("test",1, "0"),("test",1, "0"),("test",1, "0"),

("test",1, "0"),("test",1, "0"),("test",1, "0"),("test",1, "0"),
("test",1, "0"),("test",1, "0"),("test",1, "0"),("test",1, "0"),
("test",1, "0"),("test",1, "0"),("test",1, "0"),("test",1, "0"),
("test",1, "0"),("test",1, "0"),("test",1, "0"),("test",1, "0"),
("test",1, "0"),("test",1, "0"),("test",1, "0"),("test",1, "0")


  • 时间损耗

在插入上面24条数据的时候发现两者的执行效率相差比较大(近10倍的)

  方式一:

  方式二:


 

  •  扩展:

那么jdbc中的批处理的内部实现是不是采用方式二的形式来实现呢?感兴趣的朋友可以查看下该部分的源码...

  

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:mysql想要别人远程能连接

下一篇:MySQL误操作后如何快速恢复数据