Querying Slow SQL Statements
Function
This API is used to query slow SQL statements based on node information. Before calling this API:
- Learn how to authenticate this API.
- Obtain the required region and endpoint.
Constraints
This API is suitable only for nodes with CNs or DNs (primary or standby DNs).
Debugging
You can debug this API in API Explorer.
URI
POST /v3/{project_id}/instances/{instance_id}/slow-sql-list
Parameter |
Mandatory |
Description |
---|---|---|
project_id |
Yes |
Definition Project ID of a tenant in a region. To obtain the value, see Obtaining a Project ID. Constraints N/A Range The value can contain 32 characters. Only letters and digits are allowed. Default Value N/A |
instance_id |
Yes |
Definition Instance ID, which uniquely identifies an instance. Constraints N/A Range The value can contain 36 characters. Only letters and digits are allowed. Default Value N/A |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition User token. You can obtain the token by calling the IAM API used to obtain a user token. After the request is processed, the value of X-Subject-Token in the message header is the token value. Constraints N/A Range N/A Default Value N/A |
X-Language |
No |
String |
Definition Language. Constraints N/A Range
Default Value en-us |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
start_time |
Yes |
Long |
Definition Start date. Constraints The value is a 13-digit UNIX timestamp, in milliseconds. The time zone is UTC. Range N/A Default Value N/A |
end_time |
Yes |
Long |
Definition End date. Constraints The value is a 13-digit UNIX timestamp, in milliseconds. The time zone is UTC. Range N/A Default Value N/A |
instance_id |
Yes |
String |
Definition Instance ID. Constraints N/A Range N/A Default Value N/A |
threshold |
Yes |
Integer |
Definition Slow SQL threshold, in seconds. Constraints N/A Range 1–99 Default Value N/A |
node_ids |
Yes |
Array of strings |
Definition Node ID. Constraints The value cannot be left blank. |
sql_id |
No |
String |
Definition ID of a slow SQL statement. You can filter slow SQL statements by SQL ID. Constraints N/A Range N/A Default Value N/A |
multi_queries |
No |
Array of MultiMergeCondition |
Definition Query conditions for field aggregation. For details, see Table 4. Constraints Only all-AND or all-OR queries can be performed on the query field. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
Yes |
String |
Definition Name of the field to be queried. Constraints Only the character string query is supported. Range 1 to 128 characters, including letters (case-sensitive), digits, and underscores (_) Default Value N/A |
condition |
Yes |
String |
Definition Combination condition. Constraints N/A Range The value can only be and, or, AND or OR. Default Value N/A |
values |
Yes |
Array of strings |
Definition Set of multiple search criteria. The value is a list of 1 to 5 characters. Constraints N/A |
is_fuzzy |
No |
Boolean |
Definition Set of multiple search criteria. Constraints The value can only be true for fuzzy query. Range
Default Value true |
Response Parameters
Parameter |
Type |
Description |
---|---|---|
total |
Integer |
Definition Total number of slow SQL statements. Range N/A |
slow_sql_infos |
Array of objects |
Definition Slow SQL statements. For details, see Table 6. |
Parameter |
Type |
Description |
---|---|---|
db_name |
String |
Definition Database name. Range N/A |
schema_name |
String |
Definition Schema name. Range N/A |
sql_id |
String |
Definition SQL ID. Range N/A |
user_name |
String |
Definition Username. Range N/A |
node_id |
String |
Definition Node ID. Range N/A |
node_name |
String |
Definition Node name. Range N/A |
sql_text |
String |
Definition SQL template. Range N/A |
sql |
String |
Definition Complete SQL statement after variable replacement. If sql_text does not contain variable values, sql returns an empty string. Range N/A |
query_plan |
String |
Definition Execution plan. Range N/A |
calls |
Integer |
Definition Number of executions. Range N/A |
avg_exec_time |
String |
Definition Average execution duration of slow SQL statements, in seconds. Range N/A |
avg_cpu_time |
String |
Definition CPU time, in seconds. Range N/A |
avg_io_time |
String |
Definition I/O time, in seconds. Range N/A |
avg_returned_rows |
Integer |
Definition Returned rows. Range N/A |
avg_fetched_rows |
Integer |
Definition Fetched rows. Range N/A |
buffer_hit_ratio |
String |
Definition Buffer hit rate. Range N/A |
sql_hit_ratio |
String |
Definition SQL hit ratio. Range N/A |
Example Request
Querying slow SQL statements
POST https://gaussdb-opengauss.ap-southeast-1.myhuaweicloud.com/v3/0611f1bd8b00d5d32f17c017f15b599f/instances/3d39c18788b54a919bab633874c159dfin14/slow-sql-list
{
"instance_id" : "d04686c6baae4f65a742771186f47b7ain14",
"node_ids" : [ "88391813e1cb4e93899b210e880fdb1bno20" ],
"start_time" : 1686903754933,
"end_time" : 1686990154933,
"threshold" : 1,
"multi_queries": [ { "name": "query", "condition": "AND", "is_fuzzy": true, "values": [ "slelect", "from table" ] } ]
}
Example Response
Slow SQL statements queried.
{ "slow_sql_infos" : [ { "db_name": "db_tpcc", "schema_name": "db_tpcc", "sql_id" : "6789", "user_name" : "john_doe", "sql_text" : "SELECT * FROM large_table WHERE column1 = 'value';", "sql" : "", "query_plan" : "Seq Scan on large_table ...", "calls" : 5, "avg_exec_time" : "17.4015", "avg_cpu_time" : "2.6380", "avg_io_time" : "0.0000", "avg_returned_rows" : 1000, "avg_fetched_rows" : 5000, "buffer_hit_ratio" : "0.8", "sql_hit_ratio" : "0.005", "node_id" : "88391813e1cb4e93899b210e880fdb1bno20", "node_name" : "Node1" } ], "total" : 1 }
Status Codes
- Normal
- Abnormal
For details, see Status Codes.
Error Codes
For details, see Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank 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