Exporting the Top SQL Template List
Function
- This API is used to export the Top SQL template list after Top SQL is enabled.
- This function is only available for paid instances.
- The maximum query interval is one hour.
Authorization Information
Each account has permissions to call all APIs, but IAM users must have the required permissions specifically assigned.
- If you are using role/policy-based authorization, see the required permissions in Permissions Policies and Supported Actions.
- If you are using identity policy-based authorization, the following identity policy-based permissions are required.
Action
Access Level
Resource Type (*: required)
Condition Key
Alias
Dependencies
das:clouddba:listTopSql
List
Instance
-
das:clouddba:topSqlList
-
URI
GET /v3/{project_id}/instances/{instance_id}/top-sql-templates
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition Project ID of a tenant in a region To obtain this value, see Obtaining a Project ID. Constraints N/A Range The value can contain 32 characters. Only letters and digits are supported. Default Value N/A |
| instance_id | Yes | String | Definition Instance ID, which uniquely identifies an instance. You can obtain the instance ID from the instance list or instance details. Constraints N/A Range The value can contain 36 characters. Only letters and digits are allowed. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| start_at | Yes | Long | Definition Start time Constraints Unix timestamp, in milliseconds Range [0, 2^63 – 1]. The actual value depends on the query result. Default Value N/A |
| end_at | Yes | Long | Definition End time Constraints Unix timestamp, in milliseconds Range [0, 2^63 – 1]. The actual value depends on the query result. Default Value N/A |
| datastore_type | Yes | String | Definition Database type Constraints N/A Range
Default Value N/A |
| node_id | No | String | Definition Unique ID of a node. You can obtain the node ID from the node list in the instance details. Constraints N/A Range The value can contain 36 characters. Only letters and digits are allowed. Default Value N/A |
| sort | No | String | Definition Sorting field Constraints N/A Range
Default Value N/A |
| asc | No | Boolean | Definition Sorting order Constraints N/A Range
Default Value
|
| offset | No | Integer | Definition Index offset. The query starts from the next piece of data indexed by this parameter. If this parameter is set to 1 and limit is set to 10, only the second to eleventh records are displayed. Constraints N/A Range [0, 2^31-1] Default Value 0: The query starts from the first data record. |
| limit | No | Integer | Definition Number of records to be queried. If this parameter is set to 10, a maximum of 10 records can be displayed. Constraints N/A Range [1, 100] Default Value 20 |
| sql_template_id | No | String | Definition SQL template ID. Constraints N/A Range N/A Default Value N/A |
| db_name_list | No | String | Definition Database names. Use commas (,) to separate multiple values. Constraints N/A Range N/A Default Value N/A |
Request Parameters
None
Response Parameters
Status code: 200
| Parameter | Type | Description |
|---|---|---|
| top_sql_templates | Array of TopSqlTemplate objects | Definition SQL templates |
| total_count | Integer | Definition Total number of SQL templates Range [0, 2^31 – 1]. The actual value depends on the query result. |
| Parameter | Type | Description |
|---|---|---|
| sql_template | String | Definition SQL template ID Range N/A |
| sql_sample_string | String | Definition SQL sample Range N/A |
| sql_type | String | Definition SQL type Range
|
| db_name | String | Definition Database name Range N/A |
| execute_num | Long | Definition Total executions Range N/A |
| total_cost | Double | Definition Total duration (ms) Range N/A |
| avg_cost | Double | Definition Average duration (ms) Range N/A |
| avg_rows_sent | Double | Definition Average rows returned Range N/A |
| avg_rows_affected | Double | Definition Average rows affected Range N/A |
| avg_lock_time | Double | Definition Average lock wait time (ms) Range N/A |
| total_rows_examined | Double | Definition Total rows scanned Range N/A |
| avg_rows_examined | Double | Definition Average rows scanned Range N/A |
| total_cost_ratio | String | Definition Percentage of the total duration Range N/A |
| total_examined_ratio | String | Definition Percentage of scanned rows Range N/A |
| execute_num_ratio | String | Definition Percentage of execution times Range N/A |
Example Requests
Exporting the Top SQL template list
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
Example Responses
Status code: 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
} Status Codes
| Status Code | Description |
|---|---|
| 200 | Success. |
| 400 | Client error. |
| 500 | Server error. |
Error Codes
See Error Codes.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot