Example 5.2. Setting fetch size to turn cursors on and off.
Changing code to cursor mode is as simple as setting the fetch size of the Statement to the appropriate size. Setting the fetch size back to 0 will cause all rows to be cached (the default behaviour).
// make sure autocommit is off
conn.setAutoCommit(false);
Statement st = conn.createStatement();
// Turn use of the cursor on.
st.setFetchSize(50);
ResultSet rs = st.executeQuery("SELECT * FROM mytable");
while (rs.next()) {
System.out.print("a row was returned.");
}
rs.close();
// Turn the cursor off.
st.setFetchSize(0);
rs = st.executeQuery("SELECT * FROM mytable");
while (rs.next()) {
System.out.print("many rows were returned.");
}
rs.close();
// Close the statement.
st.close();
[/code]
按此方法请开发同事测试了下,果然给力。
于是动手改造了索引的这部分代码,90W 记录,完成索引大约10分钟。
而之前order by limit m,n 版本的 在测试环境跑了一个下午。 差距很大。
记于此,为后来者指路。来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/133735/viewspace-733295/ ,如需转载,请注明出处,否则将追究法律责任。