性能问题:结果集迭代 [英] Performance issue : Resultset Iteration

查看:147
本文介绍了性能问题:结果集迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人澄清我的以下问题。

I want someone to clarify my below questions.

1)目前我正在从java代码调用过程并获取结果集。要迭代500个记录,需要20秒。我尝试了各种fetchSize,如50,100,300,501,2000,4000但没有改进。有人可以对此提出建议。

1) Currently I am calling procedure from java code and getting result set. To iterate 500 hundreds records it is taking 20 secs. I tried various fetchSize like 50, 100, 300, 501, 2000, 4000 but no improvement. Can some one suggest on this.

2)使用查询代替过程会改善结果集迭代性能吗?

2)To use query instead of procedure will improve result set iteration performance ?

3)任何其他建议?

Code Snippet:

Code Snippet :

CallableStatement callableStatement =((SessionImpl)getSessionFactory().getCurrentSession()).connection().prepareCall("{ call Proc(?,?,?) }");
callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
callableStatement.setString(2,searchText.toLowerCase());
callableStatement.setInt(3, 500);

logger.debug("Before Query Execution");
callableStatement.executeUpdate();
logger.debug("After Query Execution:");
callableStatement.setFetchSize(501);
rs = (ResultSet)callableStatement.getObject(1);
logger.debug("Iterating ResultSet Starts");
Bean bean = null;
while(rs.next()){
logger.debug("some logic but commented to check performance");     
}


推荐答案

所以你的程序返回一个游标最多包含500行? ( callableStatement.setInt(3,500); )。为什么要使用复杂的方法?

So your procedure returns a cursor containing up to 500 rows? (callableStatement.setInt(3, 500);). Why do you use to complicated approach?

为什么不使用纯光标?使用生产者 - 消费者设计模式时,游标是有效的。如果你想啜饮一些大量的数据,你也可以使用COLLECTION类型。假设在小于10000条记录的情况下,集合可能比光标更有效。但是简单的纯SQL语句应该是最快的。

Why don't you use a pure cursor? Cursors are efficient when using producer-consumer design pattern. If you want to "slurp" some bulk of data, you can also use COLLECTION type. Let's say that in case of less then 10000 records a collection might be more effective than cursor. But simple pure SQL statement should be the fastest.

你应该首先确定你的瓶颈。它可以是:

You should identify you bottleneck first. It can be:


  • perf。数据库方面的问题(执行计划。)

  • 与数据库的低效通信(往返客户端 - 服务器的数量)

  • Java EE相关的东西。就像依赖注入一样,触发从DB返回的每一行。

PS:你的程序的源代码非常有帮助
PS1:如果你想使用生产者 - 消费者模式,你也应该使用FIRST_ROWS_N优化器目标。

PS: source code of your procedure would be very helpfull PS1: If you want to use producer-consumer pattern you also should use FIRST_ROWS_N optimizer goal.

这篇关于性能问题:结果集迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆