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


    • 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中的批处理的内部实现是不是采用方式二的形式来实现呢?感兴趣的朋友可以查看下该部分的源码...

      

  • 相关阅读:
    c# 遮罩
    判断当前task中的运行的activity是否为当前应用
    Chrome+SwitchySharp+myentunnel+SSH
    vps
    系统制作
    vs2010 mfc
    android ndk
    乐 Phone刷机教程(全过程)
    mysql 保留字 冲突
    mysql 存储过程
  • 原文地址:https://www.cnblogs.com/imaikce/p/6141032.html
Copyright © 2020-2023  润新知