CachedRowSet比ResultSet慢? [英] CachedRowSet slower than ResultSet?
问题描述
在我的java代码中,我使用select语句访问oracle数据库表。
我收到很多行(大约50.000行),所以 rs.next()
需要一些时间来处理所有行。
使用ResultSet,所有行的处理(rs.next)大约需要30秒
我的目标是加快这个过程,所以我改变了代码,现在使用 CachedRowSet
:<使用CachedRowSet,所有行的处理大约需要35秒
我不明白为什么 CachedRowSet
比正常的 ResultSet $慢c $ c>,因为
CachedRowSet
一次检索所有数据,而 ResultSet
每次检索数据 rs.next
被调用。
以下是代码的一部分:
try {
stmt = masterCon.prepareStatement(sql);
rs = stmt.executeQuery();
CachedRowSet crset = new CachedRowSetImpl();
crset.populate(rs);
while(rs.next()){
int countStar = iterRs.getInt(COUNT);
...
}
}最后{
//清理
}
是什么让你认为 ResultSet
每次都会检索数据 rs.next()
被调用?这取决于它的实现方式 - 如果它一次取出一块,我也不会感到惊讶;很可能是一个相当大的块。
我怀疑你基本上看到将所有数据复制到 CachedRowSet $所需的时间c $ c>和然后全部访问 - 基本上你没有任何目的进行额外的复制操作。
In my java code, I access an oracle database table with an select statement.
I receive a lot of rows (about 50.000 rows), so the rs.next()
needs some time to process all of the rows.
using ResultSet, the processing of all rows (rs.next) takes about 30 secs
My goal is to speed up this process, so I changed the code and now using a CachedRowSet
:
using CachedRowSet, the processing of all rows takes about 35 secs
I don't understand why the CachedRowSet
is slower than the normal ResultSet
, because the CachedRowSet
retrieves all data at once, while the ResultSet
retrieves the data every time the rs.next
is called.
Here is a part of the code:
try {
stmt = masterCon.prepareStatement(sql);
rs = stmt.executeQuery();
CachedRowSet crset = new CachedRowSetImpl();
crset.populate(rs);
while (rs.next()) {
int countStar = iterRs.getInt("COUNT");
...
}
} finally {
//cleanup
}
What makes you think that ResultSet
will retrieve the data each time rs.next()
is called? It's up to the implementation exactly how it works - and I wouldn't be surprised if it fetches a chunk at a time; quite possibly a fairly large chunk.
I suspect you're basically seeing the time it takes to copy all the data into the CachedRowSet
and then access it all - basically you've got an extra copying operation for no purpose.
这篇关于CachedRowSet比ResultSet慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!