All Products
Search
Document Center

AnalyticDB:DescribeBadSqlDetection

Last Updated:Aug 28, 2026

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

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

adb:DescribeBadSqlDetection

get

DBCluster

acs:adb:{#regionId}:{#accountId}:dbcluster/{#DBClusterId}

None None

Request parameters

Parameter

Type

Required

Description

Example

DBClusterId

string

Yes

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.

am-xxx

RegionId

string

Yes

The region ID.

Note

You can call the DescribeRegions operation to query the most recent region list.

cn-hangzhou

StartTime

string

No

The beginning of the time range to query. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time is in UTC.

2021-05-18T06:00:00Z

EndTime

string

No

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

2021-09-30T00:15Z

Lang

string

No

The language. Valid values:

  • zh (default): simplified Chinese.

  • en: English.

  • ja: Japanese.

  • zh-tw: traditional Chinese.

zh

Response elements

Element

Type

Description

Example

object

The response parameters.

TotalCount

string

The total number of entries returned.

5

RequestId

string

The request ID.

32C6E870-81E5-5E2A-BE7D-F9623F090DAB

DBClusterId

string

The cluster ID.

am-xxx

DetectionItems

array<object>

The detection results.

array<object>

The detection result.

Name

string

The name of the detection item.

PeakMemory OperatorCost ScanSize

Results

array<object>

The detection results.

array<object>

The detection result.

Cost

integer

The total execution duration. Unit: milliseconds.

Note

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

37

PeakMemory

integer

The peak memory usage.

1234

OperatorCost

integer

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

12345

ScanSize

integer

The amount of scanned data. Unit: bytes.

1234

OutputDataSize

integer

The amount of returned data. Unit: bytes.

1234

ProcessId

string

The query ID.

2023120808405202104101604703151654257

TotalStages

integer

The total number of stages generated.

123

DiagnosisResults

array<object>

The diagnostic results.

object

The diagnostic result.

Code

string

The diagnostic code.

FILTER_NOT_PUSHDOWN

Detail

string

The diagnostic result details.

queryconsumed a lot ofmemoryresource,Please performquerymemoryoptimization

StageId

string

The stage ID.

Stage[1]

OperatorId

string

The operator ID.

Join[234]

SQL

string

The SQL statement.

Note

For performance reasons, SQL statements longer than 5,120 characters are truncated. To download complete SQL statements that meet a query condition, call the DownloadDiagnosisRecords operation.

select * from user

PatternId

string

The SQL pattern ID.

-5978869478527645300

StartTime

string

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

2024-05-05T02:13Z

Status

string

The severity level of the detection result. Valid values:

NORMAL WARNNING CRITICAL

Message

string

The diagnostic result details.

DetectedmultipleBadSQL,please optimize

AccessDeniedDetail

string

The access denial details.

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

Examples

Success response

JSON format

{
  "TotalCount": "5",
  "RequestId": "32C6E870-81E5-5E2A-BE7D-F9623F090DAB",
  "DBClusterId": "am-xxx",
  "DetectionItems": [
    {
      "Name": "PeakMemory\nOperatorCost\nScanSize",
      "Results": [
        {
          "Cost": 37,
          "PeakMemory": 1234,
          "OperatorCost": 12345,
          "ScanSize": 1234,
          "OutputDataSize": 1234,
          "ProcessId": "2023120808405202104101604703151654257",
          "TotalStages": 123,
          "DiagnosisResults": [
            {
              "Code": "FILTER_NOT_PUSHDOWN",
              "Detail": "queryconsumed a lot ofmemoryresource,Please performquerymemoryoptimization",
              "StageId": "Stage[1]",
              "OperatorId": "Join[234]"
            }
          ],
          "SQL": "select * from user",
          "PatternId": "-5978869478527645300",
          "StartTime": "2024-05-05T02:13Z"
        }
      ],
      "Status": "NORMAL\nWARNNING\nCRITICAL",
      "Message": "DetectedmultipleBadSQL,please optimize"
    }
  ],
  "AccessDeniedDetail": "{\n    \"PolicyType\": \"AccountLevelIdentityBasedPolicy\",\n    \"AuthPrincipalOwnerId\": \"1*****************7\",\n    \"EncodedDiagnosticMessage\": \"AQIBIAAAAOPdwKY2QLOvgMEc7SkkoJfj1kvZwsaRqNYMh10Tv0wTe0fCzaCdrvgazfNb0EnJKETgXyhR+3BIQjx9WAqZryejBsp1Bl4qI5En/D9dEhcXAtKCxCmE2kZCiEzpy8BoEUt+bs0DmlaGWO5xkEpttypLIB4rUhDvZd+zwPg4EXk4KSSWSWsurxtqDkKEMshKlQFBTKvJcKwyhk62IeYly4hQ+5IpXjkh1GQXuDRCQ==\",\n    \"AuthPrincipalType\": \"SubUser\",\n    \"AuthPrincipalDisplayName\": \"2***************9\",\n    \"NoPermissionType\": \"ImplicitDeny\",\n    \"AuthAction\": \"adb:DescribeExcessivePrimaryKeys\"\n}"
}

Error codes

HTTP status code

Error code

Error message

Description

404 InvalidDBCluster.NotFound The DBClusterId provided does not exist in our records. The specified DBClusterId parameter does not exist. Make sure that the DBClusterId value is valid.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.