我需要在 sql-server 查询计划中查找操作员扫描的页数。我用了
SET STATISTICS IO ON
这返回了每个表扫描的逻辑、物理、预读页面的数量,但我需要每个操作员。
此外,我无法使用 JDBC 驱动程序读取 IO 消息,并且我有 100 多个查询要执行并记录每个操作员读取的页数。
是否有任何方法可以至少获取每个表的页数,可以由 JDBC 驱动程序访问
或者
是否有任何标志类型的东西要设置以获取在 XML 计划本身中扫描的页数。
关于 IO 消息,查询执行期间生成的信息和警告消息可以在 JDBC 中使用getWarnings
. 下面是一个准备好的语句示例。
try (
Connection con = DriverManager.getConnection("jdbc:sqlserver://yourserver:1433;databaseName=AdventureWorks;user=youruserid;password=y0urp@ssw0rd;");
PreparedStatement ps=con.prepareStatement ("SET STATISTICS IO ON;SELECT * FROM Person.Person WHERE BusinessEntityID = ?;");
) {
ps.setInt(1, 1);
ResultSet rs = ps.executeQuery();
//consume result set(s)
do {
if(!rs.isClosed()) {
while(rs.next()) {}
rs.close();
}
} while(ps.getMoreResults());
//get info and warning messages (including statistic io messages)
SQLWarning w = ps.getWarnings();
while(w != null) {
System.out.println(w.getMessage());
w = w.getNextWarning();
}
} catch (SQLException e1) {
throw e1;
}
您的其他问题在您的dba.stackexchange question 中得到更好的回答。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句