我使用spring boot和spring data jpa、hibernate和oracle。
实际上,我的表中有大约1000万条记录,我需要做一些操作,将信息写入文件,然后删除记录。
这是一个基本的sql查询
select * from zzz where status = 2;
我做了一个测试,没有做任何操作,删除了记录
long start = System.nanoTime();
int page = 0;
Pageable pageable = PageRequest.of(page, LIMIT);
Page<Billing> pageBilling = billingRepository.findAllByStatus(pageable);
while (true) {
for (Billing: pageBilling .getContent()) {
}
if (!pageBilling .hasNext()) {
break;
}
pageable = pageBilling .nextPageable();
pageBilling = billingRepository.findAllByStatus(pageable);
}
long end = System.nanoTime();
long microseconds = (end - start) / 1000;
System.out.println(microseconds + " to write");
结果很糟糕,限制为10000,耗时157分钟,100000 28分钟,数百万19分钟。
是否有更好的解决方案来提高性能?