我有下面的Java代码比较,可以比较这两个SQL查询的性能。getNamedStatistics()
打印v $ session表中的某些列,例如一致的获取,执行计数等。
尽管我无法刷新oracle的内存,所以我可以比较这两个查询的性能。
clearOracleMemory();
start = System.nanoTime();
System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
query1UsingStatement(conn);
System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
end = System.nanoTime();
System.out.println("Took: " + ((end - start) / 1000000) + "ms");
clearOracleMemory();
start = System.nanoTime();
System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
query2UsingStatement(conn);
System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
end = System.nanoTime();
System.out.println("Took: " + ((end - start) / 1000000) + "ms");
ClearOracleMemory看起来像这样:
private static void clearOracleMemory() {
try {
PreparedStatement stmt = conn.prepareStatement("alter system flush shared_pool");
ResultSet rs = stmt.executeQuery();
System.out.println("shared pool flushed");
}
catch (SQLException e) {
System.out.println("error clearing shared pool");
System.out.println(e.getMessage());
}
}
输出示例:
shared pool flushed
Named statistics --> {CPU used by this session=45, consistent gets=5613, parse count (total)=194, parse time elapsed=14, parse time cpu=14, execute count=1544}
Named statistics --> {CPU used by this session=326, consistent gets=936322, parse count (total)=724, parse time elapsed=58, parse time cpu=60, execute count=3651}
Took: 3676ms
shared pool flushed
Named statistics --> {CPU used by this session=344, consistent gets=942088, parse count (total)=851, parse time elapsed=69, parse time cpu=73, execute count=5319}
Named statistics --> {CPU used by this session=2374, consistent gets=1019846, parse count (total)=20975, parse time elapsed=1728, parse time cpu=1732, execute count=26948}
Took: 28038ms
最佳答案
是什么让您认为共享池没有被刷新?
我怀疑您将共享池和会话统计信息混淆了吗?会话统计信息统计会话中不同资源的消耗情况。刷新共享池会影响您的会话消耗多少资源(因为例如它将需要解析语句),但这显然不会重置资源消耗计数器。
我建议您重新审视分配的读数,在此详细说明。
最好的祝福
您友好的老师,您可以设置您要询问的练习
关于java - Oracle JDBC刷新共享池不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40886689/