【问题标题】:How to find number of pages scanned by the operator in sql-server query?如何在 sql-server 查询中查找操作员扫描的页数?
【发布时间】:2018-07-13 10:17:05
【问题描述】:

我需要在 sql-server 查询计划中查找操作员扫描的页数。 我用过

SET STATISTICS IO ON

返回的每个表扫描的逻辑、物理、预读页数, 但我需要每个运营商。

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

是否有任何方法可以至少获取每个表的页数,以供 JDBC 驱动程序访问

是否需要设置任何标志类型的东西来获取在 XML PLAN 本身中扫描的页数。

【问题讨论】:

    标签: sql-server jdbc sql-execution-plan


    【解决方案1】:

    关于 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 可以更好地回答您的其他问题。

    【讨论】:

    • 我犯的错误是,试图在完全迭代到结果集之前获取警告消息。我认为那是我犯的错误
    猜你喜欢
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多