更新时间:2023-07-25 GMT+08:00
分享

导出TopSQL模板列表

功能介绍

TopSQL开关打开后,导出TopSQL模板列表。该功能仅支持付费实例。查询时间间隔最长一小时。

调试

您可以在API Explorer中调试该接口。

URI

GET /v3/{project_id}/instances/{instance_id}/top-sql-templates

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。

获取方法请参见获取项目ID

instance_id

String

实例ID。

表2 Query参数

参数

是否必选

参数类型

描述

start_at

Long

开始时间(Unix timestamp),单位:毫秒。

end_at

Long

结束时间(Unix timestamp),单位:毫秒。

datastore_type

String

数据库类型。支持MySQL和GaussDB(for MySQL)。

node_id

String

节点ID。

sort

String

排序字段(executeNum:执行次数, totalCost:总耗时, avgCost:平均耗时, totalScan: 总扫描行数, avgScan:平均扫描行数)。

缺省值:avgCost

枚举值:

  • executeNum
  • totalCost
  • avgCost
  • totalScan
  • avgScan

asc

Boolean

排序顺序(true:正序, false:逆序)。

缺省值:false

offset

Integer

偏移量。从第一条数据偏移offset条数据后开始查询,默认为0(偏移0条数据,表示从第一条数据开始查询),必须为数字,不能为负数。

limit

Integer

每页记录数,默认为20,最大取值100。

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

X-Language

String

请求语言类型。

枚举值:

  • en-us
  • zh-cn

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

top_sql_templates

Array of TopSqlTemplate objects

SQL模板列表。

total_count

Integer

SQL模板总数。

表5 TopSqlTemplate

参数

参数类型

描述

sql_template

String

SQL模板。

sql_sample_string

String

SQL样本。

sql_type

String

SQL操作类型。

db_name

String

数据库名称。

execute_num

Long

总执行次数。

total_cost

Double

总耗时(ms)。

avg_cost

Double

平均耗时(ms)。

avg_rows_sent

Double

平均返回行数。

avg_rows_affected

Double

平均影响行数。

avg_lock_time

Double

平均锁等待耗时(ms)。

total_rows_examined

Double

总扫描行数。

avg_rows_examined

Double

平均扫描行数。

total_cost_ratio

String

总耗时占比。

total_examined_ratio

String

扫描行数占比。

execute_num_ratio

String

执行次数占比。

状态码: 400

表6 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

最小长度:8

最大长度:36

error_msg

String

错误描述。

最小长度:2

最大长度:512

状态码: 500

表7 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

最小长度:8

最大长度:36

error_msg

String

错误描述。

最小长度:2

最大长度:512

请求示例

导出TopSQL模板列表。

GET https://das.cn-north-1.myhuaweicloud.com/v3/054c630ff780d4cc2f40c00d7f6fb21d/instances/6243b3fcf2f948578d46ed4c52fb54eein01/top-sql-templates?start_at=1611975464337&end_at=1611979064337&node_id=fec05693c76c4f389561051db430324cno01&sort=avgCost&asc=true&datastore_type=MySQL&offset=0&limit=10

响应示例

状态码: 200

Success.

{
  "top_sql_templates" : [ {
    "db_name" : "db_01",
    "execute_num" : 30,
    "avg_rows_examined" : 0,
    "total_cost_ratio" : "100.00%",
    "avg_lock_time" : 0,
    "sql_template" : "SELECT sleep(?)",
    "avg_rows_affected" : 0,
    "avg_rows_sent" : 1,
    "avg_cost" : 5000.266666666666,
    "execute_num_ratio" : "23.81%",
    "total_examined_ratio" : "-",
    "sql_type" : "select",
    "total_cost" : 150008,
    "total_rows_examined" : 0,
    "sql_sample_string" : "select sleep(5)"
  } ],
  "total_count" : 1
}

状态码

状态码

描述

200

Success.

400

Client error.

500

Server error.

错误码

请参见错误码

分享:

    相关文档

    相关产品