如何在sql-服务器查询中找到操作员扫描的页数?

How to find number of pages scanned by the operator in sql-server query?

我需要在 sql 服务器查询计划中找到操作员扫描的页数。 我用了

SET STATISTICS IO ON

这返回了每个 table 扫描的逻辑、物理、预读页数, 但我需要每个操作员。

此外,我无法使用 JDBC 驱动程序读取 IO 消息,并且 我有 100 多个查询要执行并记录每个操作员读取的页数。

是否有任何方法可以至少获取每个 table 的页数,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 中得到解答。