All Products
Search
Document Center

Database Autonomy Service:Query governance

Last Updated:Mar 28, 2026

Database Autonomy Service (DAS) analyzes slow queries across your database instances daily at 01:00:00, classifies each SQL template by severity, and generates optimization suggestions. This gives you a structured view of which queries need immediate attention, which can be deferred, and which can be safely ignored—without manual log triage.

Prerequisites

Before you begin, ensure that:

  • Your database instance is one of the following types:

    • ApsaraDB RDS for MySQL

    • PolarDB for MySQL

    • ApsaraDB MyBase for MySQL

    • ApsaraDB RDS for PostgreSQL

  • Your database instance is deployed in the Chinese mainland, the China (Hong Kong) region, or the Singapore region.

Support for the China (Hong Kong) and Singapore regions was added on April 1, 2023.

Limitations

  • Query governance uses T+1 offline analysis. Changes you make today—such as adding the No Need to Optimize tag—take effect the following day.

  • Tags added by the system cannot be changed or removed.

  • DAS analyzes only the top 200 most frequently executed slow queries per database instance. Each instance has a maximum of 200 slow SQL templates.

Key concepts

TermDescription
Optimizable SQLSQL templates that cause slow queries and need to be optimized.
SQL templates that do not need to be optimizedSQL templates that cause slow queries, but to which DAS has automatically added the Ignored tag, or to which you have added the No Need to Optimize tag.
IgnoredSQL templates that DAS automatically excludes from optimization. These are templates that start with SHOW, CREATE, XA, COMMIT, ROLLBACK, SELECT SLEEP, or EXPLAIN.

View query governance results

  1. Log on to the DAS console.

  2. In the left-side navigation pane, choose Intelligent O&M Center > Query Governance.

  3. On the Query Governance page, use the filters at the top to scope results by time range, region, database engine, or instance ID.

The page is organized into the following sections:

Overview

Shows categorized SQL template counts and tag distributions after the daily analysis runs.

To view Failed SQL Executions, purchase DAS Enterprise Edition.

Trend chart

Shows how query governance results change over a selected time range.

Top Rankings

Shows Worst-performing Instances and Best-performing Instances.

  • Worst-performing Instances: Instances ranked in descending order by slow query count. Use this to identify which instance has the most slow queries.

  • Best-performing Instances: Instances ranked in ascending order by the change in slow query count compared to the previous day. A negative value means fewer slow queries than the day before; a positive value means more. Use this to identify where optimization efforts are having the greatest impact.

SQL to Be Optimized

Lists slow SQL templates with filtering and action options.

Filter by any combination of the following (multiple filters use AND logic):

FilterSeparatorLogic
Database nameComma (,)OR
SQL keywordSpaceAND
Rule tagMultiple selectionOR
Database account usernameComma (,)OR

For each SQL template, the following actions are available in the Actions column:

  • Suggestions: View optimization suggestions for the template.

  • Add Tag: Manually tag the template. Tags can also be applied in bulk by selecting multiple templates.

  • Sample: View slow query logs for the template.

  • Trend: View slow query log analysis details. For more information, see Slow query log analysis.

Failed SQL

Lists SQL statements that failed to execute. Requires DAS Enterprise Edition.

Filter by database name (comma-separated, OR logic) and SQL keyword (space-separated, AND logic). Click Sample in the Actions column to view details for a specific statement.

Best practices

Use tags to prioritize optimization work

DAS classifies slow SQL templates into two categories: templates that need optimization and templates that do not. Use rule tags to filter by severity and address the most critical issues first.

The following tags are added automatically by the system:

IDNameSeverityNeeds attentionDescription
NEW_SQLNew slow SQLCriticalYesSQL templates that caused slow queries within the past seven days.
DAS_IGNOREIgnoredNormalNoTemplates starting with SHOW, CREATE, XA, COMMIT, ROLLBACK, SELECT SLEEP, or EXPLAIN. DAS excludes these from optimization automatically.
FUZZY_LIKELIKE queryNormalNoTemplates using LIKE for fuzzy matching. Indexes cannot be used for these queries.
HAS_EXPRExpressions containedNormalNoTemplates containing calculation expressions. Indexes cannot be applied to the affected columns.
LARGE_IN_LISTLarge list queryNormalNoTemplates specifying more than 200 elements for the IN operator. Often generated by programs automatically. Indexes cannot be used on the involved columns.
SELECT_STARFull-column queryNormalNoTemplates that select columns without specifying conditions, causing unnecessary data retrieval.
INDEX_ADVISORIndex suggestionsNormalYesTemplates querying unindexed tables. Create indexes to accelerate these queries.
COMPLEX_JOINComplex JOIN queryNormalNoTemplates joining more than three tables. Make sure the joined fields share the same data type and are indexed.
CROSS_DBCross-database queryNormalNoTemplates querying across databases. These queries may fail after database or table migration.
SUBQUERYSubqueries includedNormalNoTemplates containing subqueries. Rewrite using JOIN for better performance.
DEEP_PAGINGDeep pagingCriticalNoTemplates using LIMIT for deep paging. Rewrite using JOIN instead.
WITHOUT_PREDICATENo predicatesCriticalYesTemplates with no predicates, triggering full table scans. Verify whether your workload requires full table scanning; if not, rewrite the template.
NULL_COMPARENull match errorCriticalNoTemplates using ISNULL() to check for NULL values. ISNULL() returns NULL when any operand is NULL, so it cannot reliably find NULL values.
COUNT_NOT_STARInvalid COUNT syntaxCriticalNoTemplates using COUNT(column) or COUNT(constant) instead of COUNT(*). Use COUNT(*), the SQL92-standard syntax, which counts all rows including those with NULL values.
LARGE_ROWS_EXAMINEDExcessive scanned rowsNormalNoTemplates scanning more than 50,000 rows on average. Use more specific filter conditions to reduce the scan range.
LARGE_ROWS_SENTExcessive returned rowsNormalNoTemplates returning more than 5,000 rows on average. Modify the template to limit the result set.
NO_ADVICENo suggestionNormalNoNo optimization suggestion is available.
PERIOD_SQLPeriodicNormalNoTemplates executed at a fixed time each day.

Before the daily analysis runs, you can manually add one of the following tags to reduce the number of templates that appear in the optimization list:

IDNameSeverityDescription
USER_IGNORENo need to optimizeNormalRemoves the template from the optimization list starting the next day.
DAS_IMPORTANTHigh-priority SQLNormalMarks the template as high priority.
DAS_NOT_IMPORTANTLow-priority SQLNormalMarks the template as low priority.
DAS_IN_PLANOptimize laterNormalMarks the template for future optimization.

Export and share optimization data

Export filtered data

Click Export in the upper-right corner of the SQL Details section to download the currently filtered SQL templates. Exported files are available for download for three days.

To distribute optimization work across teams, filter by database name or rule tag to create focused export tasks, then assign each export to the responsible owner.

Share filtered results

To share query governance data with others:

  • Select one or more SQL templates and click Batch Sharing. DAS generates a URL that shows the selected templates. Anyone with DAS permissions can open the URL to view the details.

  • Apply filters and click Share (next to Export). DAS generates a URL that shows all currently filtered templates. Anyone with DAS permissions can open the URL to view the details.

API reference

OperationDescription
CreateQueryOptimizeTagAdds one or more tags to an SQL template.
GetQueryOptimizeExecErrorStatsQueries SQL templates that fail to execute.
GetQueryOptimizeExecErrorSampleQueries failed SQL statements in an SQL template.
GetQueryOptimizeSolutionQueries optimization suggestions for an SQL template.
GetQueryOptimizeRuleListQueries the list of tags added to slow queries on a database instance.
GetQueryOptimizeDataTrendQueries trend data for query governance results.
GetQueryOptimizeDataTopQueries best-performing and worst-performing instances based on query governance data.
GetQueryOptimizeDataStatsQueries SQL template details based on query governance data.
GetQueryOptimizeTagQueries the tags of an SQL template.
GetQueryOptimizeShareUrlQueries the share URL for query governance data.