Performance issue : Resultset Iteration

不打扰是莪最后的温柔 提交于 2020-01-06 21:05:51

问题


I want someone to clarify my below questions.

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)To use query instead of procedure will improve result set iteration performance ?

3) Any other suggestion ?

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”);     
}

回答1:


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

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. issue on DB side (exec plan.)
  • inefficient communication with the database (number of round-trips client-server)
  • something Java EE related. Like dependency injection, triggered for every row returned from DB.

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.



来源:https://stackoverflow.com/questions/28742097/performance-issue-resultset-iteration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!