All Products
Search
Document Center

AnalyticDB:DescribeBadSqlDetection

Last Updated:Nov 10, 2025

Queries the bad SQL statements that affect cluster stability within a time range.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • For mandatory resource types, indicate with a prefix of * .
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
adb:DescribeBadSqlDetectionget
DBCluster
acs:adb:{#regionId}:{#accountId}:dbcluster/{#DBClusterId}
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
DBClusterIdstringYes

The cluster ID.

Note You can call the DescribeDBClusters operation to query the information about all AnalyticDB for MySQL clusters within a region, including cluster IDs.
amv-xxx
RegionIdstringYes

The region ID.

Note You can call the DescribeRegions operation to query the most recent region list.
cn-shanghai
StartTimestringYes

The beginning of the time range to query. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mmZ format. The time must be in UTC.

2022-01-23T02:18Z
EndTimestringYes

The end of the time range to query. The end time must be later than the start time. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mmZ format. The time must be in UTC.

2024-11-17T02:16Z
LangstringNo

The language. Valid values:

  • zh: simplified Chinese.
  • en: English.
zh

Response parameters

ParameterTypeDescriptionExample
object

The response parameters.

TotalCountstring

The total number of entries returned.

50
RequestIdstring

The request ID.

584CFCAE-E3C8-5BBB-B46C-724E77A830A7
DBClusterIdstring

The cluster ID.

amv-xxxx
DetectionItemsarray<object>

The queried detection items and detection results.

OpenApiFasDetectionItemobject

The queried detection item and detection result.

Namestring

The name of the detection item.

Cost
Resultsarray<object>

The detection result items.

BadSqlDiagnosisResultobject

The detection result item.

Costlong

The total execution duration. Unit: milliseconds.

Note This value is the cumulative value of the QueuedTime, TotalPlanningTime, and ExecutionTime parameters.
709
PeakMemorylong

The peak memory. Unit: bytes.

234
OperatorCostlong

The total CPU time consumed by all operators in the stage, which is equivalent to the total CPU time of the stage. You can use this parameter to determine which parts of the stage consume a large amount of computing resources. Unit: milliseconds.

2345
ScanSizelong

The amount of scanned data. Unit: bytes.

2342
OutputDataSizelong

The amount of returned data. Unit: bytes.

235433
ProcessIdstring

The query ID.

202410161002191720161451770345363xxxx
TotalStagesinteger

The total number of stages generated.

5
DiagnosisResultsarray<object>

The diagnostic result items.

BasicDiagnosisInfoobject

The diagnostic result item.

Codestring

The diagnostic code.

Large amounts of data are returned to the client.
Detailstring

The information about the diagnostic result.

Large amounts of data are returned to the client. Import the data to OSS.
StageIdstring

The stage ID.

Stage[67]
OperatorIdstring

The operator ID.

TableScan[234]
SQLstring

The SQL statement.

Note For performance considerations, an SQL statement cannot exceed 5,120 characters in length. Otherwise, the SQL statement is truncated. You can call the DownloadDiagnosisRecords operation to download the information about SQL statements that meet a query condition for an AnalyticDB for MySQL cluster, including the complete SQL statements.
SELECT * FROM device WHERE product_key = 'h66zXfxet2X' AND name = 'device@zntbtfptv5_9237117'
StartTimestring

The start time of the query. The time follows the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time is displayed in UTC.

2024-09-06T02:11:00Z
PatternIdstring

The SQL pattern ID.

3467484070025860498
Statusstring

The severity level of the detection result. Valid values:

  • NORMAL
  • WARNING
  • CRITICAL
WARNING
Messagestring

The information about the detection result.

SQL statements that result in high peak memory are detected.
AccessDeniedDetailstring

The information about the request denial.

{ "PolicyType": "AccountLevelIdentityBasedPolicy", "AuthPrincipalOwnerId": "1*****************7", "EncodedDiagnosticMessage": "AQIBIAAAAOPdwKY2QLOvgMEc7SkkoJfj1kvZwsaRqNYMh10Tv0wTe0fCzaCdrvgazfNb0EnJKETgXyhR+3BIQjx9WAqZryejBsp1Bl4qI5En/D9dEhcXAtKCxCmE2kZCiEzpy8BoEUt+bs0DmlaGWO5xkEpttypLIB4rUhDvZd+zwPg4EXk4KSSWSWsurxtqDkKEMshKlQFBTKvJcKwyhk62IeYly4hQ+5IpXjkh1GQXuDRCQ==", "AuthPrincipalType": "SubUser", "AuthPrincipalDisplayName": "2***************9", "NoPermissionType": "ImplicitDeny", "AuthAction": "adb:DescribeExcessivePrimaryKeys" }

Examples

Sample success responses

JSONformat

{
  "TotalCount": 50,
  "RequestId": "584CFCAE-E3C8-5BBB-B46C-724E77A830A7",
  "DBClusterId": "amv-xxxx",
  "DetectionItems": [
    {
      "Name": "Cost",
      "Results": [
        {
          "Cost": 709,
          "PeakMemory": 234,
          "OperatorCost": 2345,
          "ScanSize": 2342,
          "OutputDataSize": 235433,
          "ProcessId": "202410161002191720161451770345363xxxx",
          "TotalStages": 5,
          "DiagnosisResults": [
            {
              "Code": "Large amounts of data are returned to the client.",
              "Detail": "Large amounts of data are returned to the client. Import the data to OSS.",
              "StageId": "Stage[67]",
              "OperatorId": "TableScan[234]"
            }
          ],
          "SQL": "SELECT * FROM device WHERE product_key = 'h66zXfxet2X' AND name = 'device@zntbtfptv5_9237117'",
          "StartTime": "2024-09-06T02:11:00Z",
          "PatternId": 3467484070025860600
        }
      ],
      "Status": "WARNING",
      "Message": "SQL statements that result in high peak memory are detected."
    }
  ],
  "AccessDeniedDetail": {
    "PolicyType": "AccountLevelIdentityBasedPolicy",
    "AuthPrincipalOwnerId": "1*****************7",
    "EncodedDiagnosticMessage": "AQIBIAAAAOPdwKY2QLOvgMEc7SkkoJfj1kvZwsaRqNYMh10Tv0wTe0fCzaCdrvgazfNb0EnJKETgXyhR+3BIQjx9WAqZryejBsp1Bl4qI5En/D9dEhcXAtKCxCmE2kZCiEzpy8BoEUt+bs0DmlaGWO5xkEpttypLIB4rUhDvZd+zwPg4EXk4KSSWSWsurxtqDkKEMshKlQFBTKvJcKwyhk62IeYly4hQ+5IpXjkh1GQXuDRCQ==",
    "AuthPrincipalType": "SubUser",
    "AuthPrincipalDisplayName": "2***************9",
    "NoPermissionType": "ImplicitDeny",
    "AuthAction": "adb:DescribeExcessivePrimaryKeys"
  }
}

Error codes

HTTP status codeError codeError messageDescription
404InvalidDBCluster.NotFoundThe DBClusterId provided does not exist in our records.The specified DBClusterId parameter does not exist. Make sure that the DBClusterId value is valid.

For a list of error codes, visit the Service error codes.