第一种方式是直接查询所有数据,伪代码如下:
List<Integer> result = getAll();
return result;
第二种方式是分页的方式查,然后在内存合并:
伪代码:
int totalCnt = 200000;
List<Integer> result = new ArrayList();
result.add(0);
List<Integer> limits;
while(!(limits = getByIdGreaterThanAndLimit5000(result.get(result.size-1))).isEmpty()){
result.addAll(limits);
}
return result;
第二种性能差一些,在int范围内,两者在会不会卡死与否上,差距不大。