> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pawsql.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> PawSQL 是一个产品：Cloud 是公网部署形态，Engine / Optimizer / Auditor / Advisor / Patroller 是同一产品的组件与交付形态，不是彼此独立的产品。 / PawSQL is a single product: Cloud is the public deployment form, while Engine / Optimizer / Auditor / Advisor / Patroller are components and delivery forms of the same product, not separate products.
> 术语以站内术语表为准：SQL 审核对应英文 SQL Review，查询重写对应 Query Rewrite，索引推荐对应 Index Recommendation；英文内容统一用 Review，不用 Audit。 / Use the site glossary for terminology: 审核 is SQL Review, 重写 is Query Rewrite, 索引推荐 is Index Recommendation; English content uses Review, never Audit.
> 引用能力范围或版本支持时以对应页面为准；标注 unknown、或 status 非 published 的内容表示尚未经产品核实，不应作为事实引用。 / Cite capability scope and version support from the corresponding page; content marked unknown, or with a status other than published, is not yet product-verified and must not be cited as fact.

# 查询优化汇总

> 通过优化任务 ID 或名称查询优化汇总信息。

`analysisId` 和 `analysisName` 至少传一个。如果只传 `analysisName`，将按名称模糊查询最近一条匹配记录。

当优化仍在进行中时，仅返回 `status` 和 `analysisName`。




## OpenAPI

````yaml /openapi/pawsql-optimization.yaml post /getAnalysisSummary
openapi: 3.0.3
info:
  title: PawSQL 优化服务
  description: |
    PawSQL SQL 优化服务对外接口。

    PawSQL 优化引擎是为开发者和 DBA 开发的查询优化引擎，集成了数据库行业的查询优化最佳实践，
    提供强大的 SQL 审核和重写优化功能，并集成 Paw Index Advisor 索引推荐引擎为慢查询提供基于成本的索引推荐。

    ## 认证方式

    大部分接口需要通过 `userKey`（激活码）进行身份认证。
    `userKey` 可通过 `/getUserKey` 接口（邮箱密码登录）获取。

    ## 接口调用流程

    1. 调用 `/getUserKey` 获取 userKey
    2. 调用 `/createWorkspace` 创建工作空间（或直接在 `/createAnalysis` 中传入 DDL）
    3. 调用 `/createAnalysis` 或 `/createAnalysisAsync` 创建优化任务
    4. 调用 `/getAnalysisSummary` 获取优化汇总
    5. 调用 `/getStatementDetails` 获取单条 SQL 优化详情
  version: 1.0.0
  contact:
    name: PawSQL Team
    url: https://pawsql.com
  license:
    name: PawSQL
    url: https://pawsql.com
servers:
  - url: /api/v1
    description: PawSQL Server
security:
  - userKey: []
tags:
  - name: 身份认证
    description: 身份认证接口
  - name: 工作空间
    description: 工作空间管理接口
  - name: SQL优化
    description: SQL 优化任务接口
paths:
  /getAnalysisSummary:
    post:
      tags:
        - 优化任务
      summary: 查询优化汇总
      description: >
        通过优化任务 ID 或名称查询优化汇总信息。


        `analysisId` 和 `analysisName` 至少传一个。如果只传
        `analysisName`，将按名称模糊查询最近一条匹配记录。


        当优化仍在进行中时，仅返回 `status` 和 `analysisName`。
      operationId: getAnalysisSummary
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiAnalysisRequestId'
            examples:
              byId:
                summary: 按 ID 查询
                value:
                  userKey: CB698418-88B25371-67F15F01-XXXXXXXX
                  analysisId: '1730503067658043394'
              byName:
                summary: 按名称查询
                value:
                  userKey: CB698418-88B25371-67F15F01-XXXXXXXX
                  analysisName: API-ANA-20260901143022
      responses:
        '200':
          description: 优化汇总信息
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/ApiResult'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/AnalysisSummary'
              examples:
                completed:
                  summary: 优化完成
                  value:
                    code: 200
                    message: Success
                    data:
                      status: success1
                      analysisName: API-ANA-20260901143022
                      basicSummary:
                        numberOfQuery: 1
                        numberOfRewrite: 2
                        numberOfIndex: 1
                        performanceImprove: 85.5
                        summaryMarkdown: ...
                      summaryStatementInfo:
                        - analysisStmtId: '1730503078953304065'
                          stmtName: Query-1
                          stmtText: select * from organization where adm_id = 100
                          costBefore: 120.5
                          costAfter: 18.3
                          performance: 84.8
                running:
                  summary: 优化进行中
                  value:
                    code: 200
                    message: Success
                    data:
                      status: running
                      analysisName: API-ANA-20260901143022
components:
  schemas:
    ApiAnalysisRequestId:
      type: object
      description: 优化任务查询请求
      properties:
        userKey:
          type: string
          description: 激活码
          example: CB698418-88B25371-67F15F01-XXXXXXXX
        analysisId:
          type: string
          description: 优化任务 ID
        analysisName:
          type: string
          description: 优化任务名称（当 analysisId 未提供时使用，按名称模糊查询最近一条匹配记录）
    ApiResult:
      type: object
      description: 统一响应体
      properties:
        code:
          type: integer
          description: 状态码，200 表示成功
          example: 200
        message:
          type: string
          description: 描述信息
          example: Success
        data:
          description: 响应数据
    AnalysisSummary:
      type: object
      description: 优化汇总信息
      properties:
        status:
          type: string
          description: '优化状态: success0 / success1 / failed / running'
        analysisName:
          type: string
          description: 优化任务名称
        basicSummary:
          type: object
          description: 基础汇总信息
          properties:
            numberOfQuery:
              type: integer
              description: SQL 语句数量
            numberOfSyntaxError:
              type: integer
              description: 语法错误数量
            numberOfRewrite:
              type: integer
              description: 重写优化数量
            numberOfRewrittenQuery:
              type: integer
              description: 被重写的 SQL 数量
            numberOfViolations:
              type: integer
              description: 违反规则数量
            numberOfViolatedQuery:
              type: integer
              description: 违反规则的 SQL 数量
            numberOfIndex:
              type: integer
              description: 推荐索引数量
            numberOfQueryIndex:
              type: integer
              description: 使用推荐索引的 SQL 数量
            performanceImprove:
              type: number
              format: double
              description: 性能提升百分比
            summaryMarkdown:
              type: string
              description: 汇总 Markdown 报告
            summaryMarkdownZh:
              type: string
              description: 中文汇总 Markdown 报告
        summaryStatementInfo:
          type: array
          description: 语句信息列表
          items:
            $ref: '#/components/schemas/SummaryStatementInfo'
    SummaryStatementInfo:
      type: object
      description: 语句汇总信息
      properties:
        analysisStmtId:
          type: string
          description: 语句 ID（用于查询详情）
        stmtName:
          type: string
          description: 语句名称
        stmtText:
          type: string
          description: 语句 SQL 文本
        costBefore:
          type: number
          format: double
          description: 优化前成本
        costAfter:
          type: number
          format: double
          description: 优化后成本
        performance:
          type: number
          format: double
          description: 语句性能提升百分比
  securitySchemes:
    userKey:
      type: apiKey
      in: header
      name: userKey
      description: 激活码，通过 /getUserKey 接口获取

````