13.SQL必知必會第14課 組合查詢(union )
阿新 • • 發佈:2021-01-20
逐條插入
逐條插入10萬條資料到本地mysql資料庫(mac本、16G)耗時184474 ms
@Test public void testCreate() { long initId = 3000L; long start = System.currentTimeMillis(); System.out.println("開始時間:"+ start); for (int i = 0; i < 100000; i++) { long id = initId + i; Org org = new Org(); org.setId(id); org.setOrgName("this is org:" + id); org.setShowFlag(EnumShowFlag.SHOW); org.setCreator(-1L); org.setCreateTime(new Date()); org.setUpdator(-1L); org.setUpdateTime(new Date()); org.setDelFlag(false); orgMapper.create(org); } System.out.println("插入時間:"+ (System.currentTimeMillis()-start)); }
批量插入
批量插入10萬條資料到本地mysql資料庫(mac本、16G)耗時16096 ms
@Test public void testCreateBatch() { long start = System.currentTimeMillis(); int totalPage = PageUtil.totalPage(100000, 20); for (int i = 0; i < totalPage; i++) { int begin = i * 20 + 3000; int end = (i + 1) * 20 + 2999; List<Org> list = new ArrayList(20); for (long j = begin; j <= end; j++) { Org org = new Org(); org.setId(j); org.setOrgName("this is org:" + j); org.setShowFlag(EnumShowFlag.SHOW); org.setCreator(-1L); org.setCreateTime(new Date()); org.setUpdator(-1L); org.setUpdateTime(new Date()); org.setDelFlag(false); list.add(org); } orgMapper.createBatch(list); } System.out.println("插入時間:"+ (System.currentTimeMillis()-start)); }
逐條更新
逐條更新10萬條資料到本地mysql資料庫(mac本、16G)耗時180437ms
@Test public void testUpdate() { long start = System.currentTimeMillis(); for (long i = 3000; i < 103000; i++) { Org org = new Org(); org.setId(i); org.setOrgName("this is org-1:" + i); orgMapper.updateBySelective(org); } System.out.println("修改時間:"+ (System.currentTimeMillis()-start)); }
批量更新
批量更新10萬條資料到本地mysql資料庫(mac本、16G)耗時29997 ms
@Test
public void testUpdateBatch() {
long start = System.currentTimeMillis();
int totalPage = PageUtil.totalPage(100000, 20);
for (int i = 0; i < totalPage; i++) {
int begin = i * 20 + 3000;
int end = (i + 1) * 20 + 2999;
List<Org> list = new ArrayList(20);
for (long j = begin; j < end; j++) {
Org org = new Org();
org.setId(j);
org.setOrgName("this is org-2:" + j);
list.add(org);
}
orgMapper.updateBatchBySelective(list);
}
System.out.println("修改時間:"+ (System.currentTimeMillis()-start));
}