发布时间:2019-09-01 09:52:31编辑:auto阅读(1598)
1、传统方式导入,一万条数据的导入(46s)
$sqlite_db = new PDO('sqlite:sqlitedata.db', 'gongz', 'gongz', []); $start = time(); $n = 0; while ($n < 100000) { $n ++; $sql = "INSERT INTO `result_data` (`buguid`, `buname`, `签约金额_万`, `认购金额_万`, `认购套数_万`, `date`, `number1`, `number2`, `rp_buname_95938`, `rp_type_95938`, `rp_parentguid_95938`, `rp_levelcode_95938`) VALUES ('871709c2-083c-e511-80c0-00155d0a6f23', '名称', '31', '547', '776', '2015-12-07 00:00:00', '123.7890', '456.5678', '名称', '4', 'e64c7c15-7ac9-406c-9969-d41aeebf3a09', 'a.aa.001.01')"; $sqlite_db->exec($sql); } echo time() - $start;
2、传统方式导入,关闭写如磁盘的检查,一万条数据的导入(10s)
$sqlite_db = new PDO('sqlite:sqlitedata.db', 'gongz', 'gongz', []); $start = time(); $n = 0; $sqlite_db->exec('PRAGMA synchronous = OFF;'); while ($n < 10000) { $n ++; $sql = "INSERT INTO `result_data` (`buguid`, `buname`, `签约金额_万`, `认购金额_万`, `认购套数_万`, `date`, `number1`, `number2`, `rp_buname_95938`, `rp_type_95938`, `rp_parentguid_95938`, `rp_levelcode_95938`) VALUES ('871709c2-083c-e511-80c0-00155d0a6f23', '名称', '31', '547', '776', '2015-12-07 00:00:00', '123.7890', '456.5678', '名称', '4', 'e64c7c15-7ac9-406c-9969-d41aeebf3a09', 'a.aa.001.01')"; $sqlite_db->exec($sql); } echo time() - $start;
3、开启事务,一万条数据的导入(0s)
$sqlite_db = new PDO('sqlite:sqlitedata.db', 'gongz', 'gongz', []); $start = time(); $n = 0; $sqlite_db->beginTransaction(); while ($n < 10000) { $n ++; $sql = "INSERT INTO `result_data` (`buguid`, `buname`, `签约金额_万`, `认购金额_万`, `认购套数_万`, `date`, `number1`, `number2`, `rp_buname_95938`, `rp_type_95938`, `rp_parentguid_95938`, `rp_levelcode_95938`) VALUES ('871709c2-083c-e511-80c0-00155d0a6f23', '名称', '31', '547', '776', '2015-12-07 00:00:00', '123.7890', '456.5678', '名称', '4', 'e64c7c15-7ac9-406c-9969-d41aeebf3a09', 'a.aa.001.01')"; $sqlite_db->exec($sql); } $sqlite_db->commit(); echo time() - $start;
另外关于sqlite主键id的小技巧:
在创建表的时候,可以不用指定主键,sqlite默认会有一个隐藏的rowid字段存在,只需要在select的时候在字段中将rowid as成一个字段名称就可以使用了
上一篇: MyBatis3一个查询DAO的实现
下一篇: unity3d纹理格式设置
47971
46556
37478
34861
29435
26090
25049
20069
19694
18164
5894°
6533°
6041°
6050°
7165°
6000°
6070°
6550°
6513°
7897°