---
schema_version: 1
id: new-slow-query-digests-between-adjacent-windows-in-premium-cluster
title: New slow-query top10 digests between adjacent Beijing windows in the primary
  premium cluster
status: active
owner: codex
evaluation:
  mode: adhoc_evidence
environment:
  profile: stable-premium
  cluster_label: premium-main
  cluster_id: '10748116073341772391'
  cluster_type: premium
  tidb_version: v8.5.x
  parent_id: '2026948324023603200'
time_window:
  resolved_by_output: resolved_window
runtime:
  hooks:
  - id: resolve_runtime_window
    stage: before_acp
    kind: python_script
    path: runtime_hook.py
    output_id: resolved_window
    args:
    - resolve-window
    - "--cluster-id"
    - "{{environment.cluster_id}}"
    - "--cluster-label"
    - "{{environment.cluster_label}}"
    - "--local-hour"
    - '11'
    - "--local-minute"
    - '0'
    - "--duration-minutes"
    - '10'
    - "--top-n"
    - '10'
  - id: build_runtime_reference
    stage: before_judge
    kind: python_script
    path: runtime_hook.py
    output_id: reference_answer
    args:
    - build-reference
    - "--cluster-id"
    - "{{environment.cluster_id}}"
    - "--cluster-label"
    - "{{environment.cluster_label}}"
    - "--start"
    - "{{runtime.resolved_window.current_window.start}}"
    - "--end"
    - "{{runtime.resolved_window.current_window.end}}"
    - "--top-n"
    - '10'
prompt:
  text: |
    帮我比较这个 Premium 集群（{{environment.cluster_id}}）在下面两个北京时间窗口里的慢查询 top10 SQL digest：

    - previous window: {{runtime.resolved_window.previous_window.start}} 到 {{runtime.resolved_window.previous_window.end}}
    - current window: {{runtime.resolved_window.current_window.start}} 到 {{runtime.resolved_window.current_window.end}}

    这两个窗口对应的 Unix epoch 秒也固定如下，必须直接使用，不能自己重新换算成别的时间：
    - previous window epoch: `{{runtime.resolved_window.previous_window.start_ts}}` 到 `{{runtime.resolved_window.previous_window.end_ts}}`
    - current window epoch: `{{runtime.resolved_window.current_window.start_ts}}` 到 `{{runtime.resolved_window.current_window.end_ts}}`

    规则严格如下：
    1. 只用 `slow query logs` 来做统计。
    2. 查询时必须使用上面给出的精确时间窗口，不能改成别的 UTC 时间，也不能自行平移时区。
    3. top10 的定义是：按 `sql digest` 聚合后统计出现次数，按出现次数从高到低排序取前 10。
    4. 如果某个 digest 出现在 current top10 但不在 previous top10，就把它当作新增 digest。
    5. `sql_statement` 字段使用这个 digest 的一条 sample SQL，压成单行，最多保留前 200 个字符。

    我只看最后结果。最终只输出一个 `json` 代码块，字段必须严格为：
    `cluster_id`、`comparison`、`evidence_sufficient`、`new_sql_digests`

    `new_sql_digests` 必须按下面的规则排序：
    1. 先按 `occurrence_count` 从高到低；
    2. 如果 `occurrence_count` 一样，再按 `sql_digest` 字典序。

    `new_sql_digests` 里的每个元素都只能包含：
    `sql_digest`、`sql_statement`、`occurrence_count`

    不要输出额外字段，不要输出额外解释，也不要把说明写进 JSON。

    JSON 结构如下：

    ```json
    {
      "cluster_id": "10748116073341772391",
      "comparison": {
        "previous_window": {
          "start": "2026-01-01T02:50:00Z",
          "end": "2026-01-01T03:00:00Z"
        },
        "current_window": {
          "start": "2026-01-01T03:00:00Z",
          "end": "2026-01-01T03:10:00Z"
        }
      },
      "evidence_sufficient": true,
      "new_sql_digests": [
        {
          "sql_digest": "18576e217f5f93fa2a934f84290447caa4b783cab493503c4ad71c912ea16930",
          "sql_statement": "select * from orders where tenant_id = ? and status = ?",
          "occurrence_count": 2492
        }
      ]
    }
    ```

    如果证据不足，请把 `evidence_sufficient` 设为 `false`，并把 `new_sql_digests` 设为空数组。
tags:
- slow-query
- structured-output
- adhoc-evidence
- premium
case_tier: P1
cost_tier: low
followup:
  scheduled_max_followups: 0
execution:
  acp_bash_timeout_s: 300
