简体   繁体   English

Java - DB2 性能改进

[英]Java - DB2 Performance Improvements

We have a SELECT statement which will take approx.我们有一个 SELECT 声明,大约需要。 3 secs to execute. 3 秒执行。 We are calling this DB2 query inside a nested While loop.我们在嵌套的 While 循环中调用此 DB2 查询。

Ex:前任:

While(hashmap1.hasNext()){ while(hashmap2.hasNext()){ SQL Query } } While(hashmap1.hasNext()){ while(hashmap2.hasNext()){ SQL 查询 } }

Problem is, the outer While loop will execute approx.问题是,外部 While 循环将执行大约。 1200 times and inner While loop will execute 200 times. 1200 次,内部 While 循环将执行 200 次。 Which means the SQL will be called 1200*200 = 240,000 times.这意味着 SQL 将被调用 1200*200 = 240,000 次。 Approx.大约。 each iteration of Outer While loop will take 150 secs. Outer While 循环的每次迭代将花费 150 秒。 So, 1200 * 150 secs = 50 hrs.所以,1200 * 150 秒 = 50 小时。

We can afford only around 12-15hrs of time, before we kick off the next process.在我们开始下一个过程之前,我们只能承受大约 12-15 小时的时间。

Is there any way to do this process quickly?有没有办法快速完成这个过程? Any new technology which can help us in fetching these records faster from DB2.任何可以帮助我们更快地从 DB2 获取这些记录的新技术。

Any help would be highly appreciated.任何帮助将不胜感激。

Note: We already looked into all possible ways to cut down the no.of iterations.注意:我们已经研究了所有可能的方法来减少迭代次数。

Sounds to me like you're trying to use the middle tier for something that the database itself is better suited for.在我看来,您正在尝试将中间层用于数据库本身更适合的东西。 It's a classic "N+1" query problem.这是一个经典的“N+1”查询问题。

I'd rewrite this logic to execute entirely on the database as a properly indexed JOIN.我将重写此逻辑以完全在数据库上作为正确索引的 JOIN 执行。 That'll not only cut down on all that network back and forth, but it'll bring the database optimizer to bear and save you the expense of bringing all that data to the middle tier for processing.这不仅会减少所有来回的网络,而且还会让数据库优化器承担并节省您将所有数据带到中间层进行处理的费用。

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

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