简体   繁体   English

结果集需要很长时间来处理来自 Oracle 的大数据

[英]Result set takes long to process big data from Oracle

In an Oracle db, I have a query select * from tablehistory在 Oracle 数据库中,我有一个select * from tablehistory

  1. The query can run fast and returns 500,000 records.该查询可以快速运行并返回 500,000 条记录。 That's not an issue.那不是问题。
  2. The challenge is the result set takes a long long time to loop over.挑战在于结果集需要很长时间才能循环。
  3. How do I solve that result set taking a long time to loop over?如何解决需要很长时间循环的结果集?
  4. The result set data, I plan to save it into a hash map/do processing.结果集数据,我打算保存成hash map/do处理。
  5. Below code, start 1, 2, 3 print fast, start 4 takes long time to print;下面的代码,start 1、2、3打印速度快,start 4打印时间长; it's slow很慢

How do I speed up my code?如何加快我的代码?

String mayquery="select * from tablehistory";   
try {
        System.out.println("# start 0");
        PreparedStatement preparedStatement = con.prepareStatement(mayquery);
        System.out.println("# start 1");
        ResultSet resultSet = preparedStatement.executeQuery();
        System.out.println("# start 2");
        int count =0;
        System.out.println("# start 3");
        while (resultSet.next()) {
            System.out.println("start 4 count:"+count);
            count++;
        }
        System.out.println("# end a");
        System.out.println("count:"+count);
    } catch(Exception e) {
        
    }
  1. Try setting resultSet.setFetchSize(int) this to a higher value.尝试将 resultSet.setFetchSize(int) 设置为更高的值。 By default, it is set as 10. This parameter controls number of network calls from server to DB and can increase performance when used optimally.默认情况下,它设置为 10。此参数控制从服务器到 DB 的网络调用次数,并且在最佳使用时可以提高性能。
  2. Check for network latency.检查网络延迟。
  3. System.out.println() is a heavy operation. System.out.println() 是一个繁重的操作。 Rather than printing this each time, try printing a line for an interval.与其每次都打印,不如尝试在一段时间内打印一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM