Queries information about SQL templates based on query governance data.

  • If you use an Alibaba Cloud SDK, make sure that the aliyun-sdk-core version is later than V2.1.8. We recommend that you use the latest version.
  • The version of your Database Autonomy Service (DAS) SDK must be V2.1.8 or later.
  • If you use an SDK to call API operations of DAS, you must set the region ID to cn-shanghai.
  • This operation supports the following database engines:
    • ApsaraDB RDS for MySQL
    • PolarDB for MySQL
    • ApsaraDB RDS for PostgreSQL

Request parameters

ParameterTypeRequiredExampleDescription
ActionStringYesGetQueryOptimizeDataStats

The operation that you want to perform. Set the value to GetQueryOptimizeDataStats.

EngineStringYesMySQL

The database engine. Valid values:

  • MySQL
  • PolarDBMySQL
  • PostgreSQL
InstanceIdsStringNorm-2ze8g2am97624****

The instance IDs. Separate multiple IDs with commas (,).

TagNamesStringNoNone

A reserved parameter.

KeywordsStringNoselect update

The keywords of the SQL templates. Separate multiple keywords with spaces.

LogicalOperatorStringNoor

The logical relationship between multiple keywords. Valid values:

  • or
  • and
RulesStringNoDAS_NOT_IMPORTANT

The tags that are used to filter SQL templates. Separate multiple tags with commas (,). For more information, see Query governance.

DbNamesStringNotestdb01

The name of the database to be queried.

TimeStringYes1642953600000

The time range to query. Specify the time in the UNIX timestamp format. Unit: milliseconds.

PageSizeStringNo10

The maximum number of entries to return on each page. Default value: 10.

PageNoStringNo1

The number of the page to return. Pages start from page 1. Default value: 1.

OrderByStringNocount

The field by which to sort the returned entries. Default value: count. Valid values:

  • count: the number of executions.
  • maxQueryTime: the longest execution time.
  • avgQueryTime: the average execution time.
  • maxLockTime: the longest lock wait time.
  • avgLockTime: the longest lock wait time.
  • maxRowsExamined: the largest number of scanned rows.
  • avgRowsExamined: the average number of scanned rows.
  • maxRowsSent: the largest number of returned rows.
  • avgRowsSent: the average number of returned rows.
AscStringNotrue

Specifies whether to sort the returned entries in ascending order. Default value: true. Valid values:

  • true
  • false
OnlyOptimizedSqlStringNofalse

Specifies whether to query SQL templates that only need to be optimized. Default value: false. Valid values:

  • true: Only SQL templates that need to be optimized are queried.
  • false: All SQL templates are queried.
SqlIdsStringNo2e8147b5ca2dfc640dfd5e43d96a****

The SQL template ID. You can query the ID of a template by calling the GetQueryOptimizeExecErrorStats operation.

RegionStringNocn-china

The region in which the instance resides. Valid values:

  • cn-china: Chinese mainland
  • cn-hongkong: China (Hong Kong)
  • ap-southeast-1: Singapore

This parameter takes effect only when InstanceIds is left empty. If you leave InstanceIds empty, the system obtains data from the region set by Region. By default, Region is set to cn-china. If you specify InstanceIds, Region does not take effect and the system obtains data from the region in which the first specified instance resides.

Note If your instances reside in the regions inside the Chinese mainland, set this parameter to cn-china.
UserStringNotestUser

The account of the database to be queried.

Response parameters

ParameterTypeExampleDescription
CodeString200

The HTTP status code returned.

MessageStringSuccessful

The message that is returned for the request.

DataObject

The details of the SQL templates.

TotalLong10

The total number of returned entries.

PageNoIntegerNone

A reserved parameter.

PageSizeIntegerNone

A reserved parameter.

ExtraStringNone

A reserved parameter.

ListArray of QueryOptimizeDataStats

The information about the SQL templates.

InstanceIdStringrm-2ze8g2am97624****

The instance ID.

DbnameStringtestdb01

The name of the database to which the SQL template belongs.

SqlIdString2e8147b5ca2dfc640dfd5e43d96a****

The ID of the SQL template.

SqlTypeStringINSERT

The type of the SQL statement.

PsqlStringselect 1

The SQL template.

SqlSampleStringselect 2

The sample query that took the longest time to execute.

CountInteger100

The number of times that the SQL template is executed.

MaxQueryTimedouble1.1

The longest query execution time. Unit: seconds.

AvgQueryTimedouble1.1

The average query execution time. Unit: seconds.

MaxLockTimedouble0.1

The longest lock wait time. Unit: seconds.

AvgLockTimedouble0.1

The average lock wait time. Unit: seconds.

MaxRowsExaminedLong100000

The largest number of scanned rows.

AvgRowsExamineddouble100.1

The average number of scanned rows.

MaxRowsSentLong10000

The largest number of returned rows.

AvgRowsSentdouble100.1

The average number of returned rows.

MaxRowsAffectedLong10000

The largest number of rows affected by the SQL template.

Note If this parameter is not collected, -1 is returned.
AvgRowsAffecteddouble100.1

The average number of rows affected by the SQL template.

Note If this parameter is not collected, -1 is returned.
RuleListArray of Rules

The information about the tags.

NameStringDAS_NOT_IMPORTANT

The tag name. For more information, see Query governance.

TypeStringPredefined

The type of the tag. Valid values:

  • Predefined
  • UserDefined
UserStringtestUser

The account of the database.

RequestIdStringB6D17591-B48B-4D31-9CD6-9B9796B2****

The request ID.

SuccessStringtrue

Indicates whether the request was successful. Valid values:

  • true
  • false

Examples

Sample requests

http(s)://das.cn-shanghai.aliyuncs.com/?Action=GetQueryOptimizeDataStats
&Engine=MySQL
&InstanceIds=rm-2ze8g2am97624****
&TagNames=None
&Keywords=select update
&LogicalOperator=or
&Rules=DAS_NOT_IMPORTANT
&DbNames=testdb01
&Time=1642953600000
&PageSize=10
&PageNo=1
&OrderBy=count
&Asc=true
&OnlyOptimizedSql=false
&SqlIds=2e8147b5ca2dfc640dfd5e43d96a****
&Region=cn-china
&User=testUser
&Common request parameters

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<GetQueryOptimizeDataStatsResponse>
    <Code>200</Code>
    <Message>Successful</Message>
    <Data>
        <Total>10</Total>
        <Extra>None</Extra>
        <List>
            <InstanceId>rm-2ze8g2am97624****</InstanceId>
            <Dbname>testdb01</Dbname>
            <SqlId>2e8147b5ca2dfc640dfd5e43d96a****</SqlId>
            <SqlType>INSERT</SqlType>
            <Psql>select 1</Psql>
            <SqlSample>select 2</SqlSample>
            <Count>100</Count>
            <MaxQueryTime>1.1</MaxQueryTime>
            <AvgQueryTime>1.1</AvgQueryTime>
            <MaxLockTime>0.1</MaxLockTime>
            <AvgLockTime>0.1</AvgLockTime>
            <MaxRowsExamined>100000</MaxRowsExamined>
            <AvgRowsExamined>100.1</AvgRowsExamined>
            <MaxRowsSent>10000</MaxRowsSent>
            <AvgRowsSent>100.1</AvgRowsSent>
            <MaxRowsAffected>10000</MaxRowsAffected>
            <AvgRowsAffected>100.1</AvgRowsAffected>
            <RuleList>
                <Name>DAS_NOT_IMPORTANT</Name>
                <Type>Predefined</Type>
            </RuleList>
        </List>
    </Data>
    <RequestId>B6D17591-B48B-4D31-9CD6-9B9796B2****</RequestId>
    <Success>true</Success>
</GetQueryOptimizeDataStatsResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "Code" : "200",
  "Message" : "Successful",
  "Data" : {
    "Total" : 10,
    "Extra" : "None",
    "List" : [ {
      "InstanceId" : "rm-2ze8g2am97624****",
      "Dbname" : "testdb01",
      "SqlId" : "2e8147b5ca2dfc640dfd5e43d96a****",
      "SqlType" : "INSERT",
      "Psql" : "select 1",
      "SqlSample" : "select 2",
      "Count" : 100,
      "MaxQueryTime" : 1.1,
      "AvgQueryTime" : 1.1,
      "MaxLockTime" : 0.1,
      "AvgLockTime" : 0.1,
      "MaxRowsExamined" : 100000,
      "AvgRowsExamined" : 100.1,
      "MaxRowsSent" : 10000,
      "AvgRowsSent" : 100.1,
      "MaxRowsAffected" : 10000,
      "AvgRowsAffected" : 100.1,
      "RuleList" : [ {
        "Name" : "DAS_NOT_IMPORTANT",
        "Type" : "Predefined"
      } ]
    } ]
  },
  "RequestId" : "B6D17591-B48B-4D31-9CD6-9B9796B2****",
  "Success" : "true"
}

Error codes

HTTP status codeError codeError messageDescription
400InvalidParamsThe request parameters are invalid.The error message returned because the specified request parameters are invalid.

For a list of error codes, see Service error codes.