获取大型查询的查询计划状态

实时分析用于监控大型(长时间运行的)查询。请按照以下步骤监控大型查询的计划:

  1. 通过查询系统表 CURRENT_SESSION 获取要分析的查询计划的语句和事务 ID:

    => SELECT transaction_id, statement_id from current_session;
      transaction_id   | statement_id
    -------------------+--------------
     45035996273955001 |            4
    (1 row)
    
  2. 运行查询:

    => SELECT * FROM t1 JOIN t2 ON x=y JOIN ext on y=z;
    
  3. 查询系统表 QUERY_PLAN_PROFILES,并对 transaction_id、statement_id、path_id 和 path_line_index 列进行排序。

    => SELECT ... FROM query_plan_profiles WHERE transaction_id=45035996273955001 and statement_id=4
       ORDER BY transaction_id, statement_id, path_id, path_line_index;
    

也可以使用 Linux watch 命令监控长时间运行的查询(请参阅实时分析)。

示例

以下一系列命令会为长时间运行的查询创建表,然后查询系统表 QUERY_PLAN_PROFILES

  1. 创建名为 longq 的表:

    => CREATE TABLE longq(x int);
    CREATE TABLE
    => COPY longq FROM STDIN;
    Enter data to be copied followed by a newline.
    End with a backslash and a period on a line by itself.
    >> 1
    >> 2
    >> 3
    >> 4
    >> 5
    >> 6
    >> 7
    >> 8
    >> 9
    >> 10
    >> \.
    => INSERT INTO longq SELECT f1.x+f2.x+f3.x+f4.x+f5.x+f6.x+f7.x
          FROM longq f1
          CROSS JOIN longq f2
          CROSS JOIN longq f3
          CROSS JOIN longq f4
          CROSS JOIN longq f5
          CROSS JOIN longq f6
          CROSS JOIN longq f7;
      OUTPUT
    ----------
     10000000
    (1 row)
    => COMMIT;
    COMMIT
    
  2. 通过使用 vsql \o 命令禁止查询在终端窗口上输出:

    => \o /home/dbadmin/longQprof
    
  3. 查询新表:

    => SELECT * FROM longq;
    
  4. 获取事务和语句 ID:

    => SELECT transaction_id, statement_id from current_session;
      transaction_id   | statement_id
    -------------------+--------------
     45035996273955021 |            4
    (1 row)
    
  5. 关闭 \o 命令以便 Vertica 继续将查询计划信息保存到您已指定的文件。或者,使其保持打开状态并在查询系统表 QUERY_PLAN_PROFILES 后检查该文件。

    => \o
    
  6. 查询系统表 QUERY_PLAN_PROFILES

    => SELECT
         transaction_id,
         statement_id,
         path_id,
         path_line_index,
         is_executing,
         running_time,
         path_line
       FROM query_plan_profiles
       WHERE transaction_id=45035996273955021 AND statement_id=4
       ORDER BY transaction_id, statement_id, path_id, path_line_index;