English 中文(简体)
为什么从Oracle储存的程序中回收生物浓缩物如此缓慢?
原标题:Why is retrieving a ResultSet from Oracle stored procedure so slow?

我必须改进一些法典,其中要求从 Java方案获得甲骨质存储程序。 目前,这部法典确实很缓慢:在我的开发机器上多达8秒。 在同一台机器上,如果我直接打电话,回答同样的处理,并填写同样的数据,则用100米以下。

该守则建立了可控声明,将产出参数之一登记为甲骨质 cur,然后利用声明的“目标”方法检索治疗器,并将其归为ResultSet:

cstmt = conn.prepareCall("{ call PKG_ESPECEW.P_ListEspece( ?, ?, ?, ?, ?, ? ) }");
cstmt.registerOutParameter(4, oracle.jdbc.OracleTypes.CURSOR);
[...]
cstmt.executeQuery();
rs = (ResultSet)cstmt.getObject(4);
rs.setFetchSize(1000); //supposed to help ?

options = new HashMap<String, String>(1000);
rs.next() //added that to measure exactly the length of the first call

while(rs.next()) {
    [...]
}

我在守则中设置了一些时间段,以了解其中哪一部分是这么长时间的。 其结果:第1次电话rs.next(<>>/code>正在处理各种秒。 成果集为平均数,从10到几千分。 正如我以前说过的那样,处理来自定期编写的声明的类似结果集,视规模而定,需要10-100个。

法典中是否有任何错误? 我如何改进? 如果我提出任何其他解决办法,那么我确实把卡勒克作为批评点,但我更喜欢一种解决办法,使我不能重新制定所有程序!

这里是储存程序的定义:

PROCEDURE P_ListEspece(P_CLT_ID IN ESPECE.ESP_CLT_ID%TYPE,     -- Langue de l utilisateur
                        P_ESP_GROUP_CODE IN ESPECE.ESP_CODE%TYPE,-- Code du groupe ou NULL
                        P_Filter IN VARCHAR2,                   -- Filtre de la requête
                        P_Cursor OUT L_CURSOR_TYPE,             -- Curseur
                        P_RecordCount OUT NUMBER,               -- Nombre d enregistrement retourne
                        P_ReturnStatus OUT NUMBER);              -- Code d erreur
最佳回答

“我认为程序已经执行,然后将结果储存在矿石服务器的记忆中,最后通过曲线和结果集以及JDBC向客户(java的 app)传送。”

That s incorrect. What oracle returns as a cursor is basically a pointer to a query (all ready with any bind variables). It has not materialized the result set in memory. It could be a massive result set of millions/billions of rows.

因此,要取得成果需要很长时间,这很可能是一个缓慢的问题。

问题回答

很明显,所储存的程序正在进行一些数据转换/数据转换(例如int<>/code> <->varchar)。 众所周知,如果是大型表格,则需要大量时间。 • 确保你在SP论点中宣布正确的数据类型,并在<编码>可核查的国家上确定正确的数据类型。

在 Java以外执行这一程序需要多长时间? * 附加说明:

var ref refcursor
var cnt number
var status number
exec p_listespece (xx, yy, zz, :ref, :cnt, :status);--replace with actual values
print :ref

如果需要10-100多ms,你的问题可能来自所储存的程序。

I had the same problem, we solved (me and the oracle dedicated guy) by changing the returned parameter from a cursor to a varchar, that was the plain query the stored was executing internally. this was an huge implementation, I don t know if this is applicable for your scenario.

The snippet :

......

String sql = "call MyStored(?,?,?,?)";
CallableStatement st = Conn.prepareCall(sql);
st.setInt(1, 10);
st.setInt(2, 20);
st.setInt(3, 30);
st.registerOutParameter(4, OracleTypes.VARCHAR);

st.execute();

String query = (String) st.getObject(4);
Statement stmt = Conn.createStatement();
rs = stmt.executeQuery(query);
[...]
//work with resultset
[...]
stmt.close();
stmt = null;

......





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...