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
| Term | Description |
|---|---|
| Optimizable SQL | SQL templates that cause slow queries and need to be optimized. |
| SQL templates that do not need to be optimized | SQL 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. |
| Ignored | SQL 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
Log on to the DAS console.
In the left-side navigation pane, choose Intelligent O&M Center > Query Governance.
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):
| Filter | Separator | Logic |
|---|---|---|
| Database name | Comma (,) | OR |
| SQL keyword | Space | AND |
| Rule tag | Multiple selection | OR |
| Database account username | Comma (,) | 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:
| ID | Name | Severity | Needs attention | Description |
|---|---|---|---|---|
| NEW_SQL | New slow SQL | Critical | Yes | SQL templates that caused slow queries within the past seven days. |
| DAS_IGNORE | Ignored | Normal | No | Templates starting with SHOW, CREATE, XA, COMMIT, ROLLBACK, SELECT SLEEP, or EXPLAIN. DAS excludes these from optimization automatically. |
| FUZZY_LIKE | LIKE query | Normal | No | Templates using LIKE for fuzzy matching. Indexes cannot be used for these queries. |
| HAS_EXPR | Expressions contained | Normal | No | Templates containing calculation expressions. Indexes cannot be applied to the affected columns. |
| LARGE_IN_LIST | Large list query | Normal | No | Templates specifying more than 200 elements for the IN operator. Often generated by programs automatically. Indexes cannot be used on the involved columns. |
| SELECT_STAR | Full-column query | Normal | No | Templates that select columns without specifying conditions, causing unnecessary data retrieval. |
| INDEX_ADVISOR | Index suggestions | Normal | Yes | Templates querying unindexed tables. Create indexes to accelerate these queries. |
| COMPLEX_JOIN | Complex JOIN query | Normal | No | Templates joining more than three tables. Make sure the joined fields share the same data type and are indexed. |
| CROSS_DB | Cross-database query | Normal | No | Templates querying across databases. These queries may fail after database or table migration. |
| SUBQUERY | Subqueries included | Normal | No | Templates containing subqueries. Rewrite using JOIN for better performance. |
| DEEP_PAGING | Deep paging | Critical | No | Templates using LIMIT for deep paging. Rewrite using JOIN instead. |
| WITHOUT_PREDICATE | No predicates | Critical | Yes | Templates with no predicates, triggering full table scans. Verify whether your workload requires full table scanning; if not, rewrite the template. |
| NULL_COMPARE | Null match error | Critical | No | Templates using ISNULL() to check for NULL values. ISNULL() returns NULL when any operand is NULL, so it cannot reliably find NULL values. |
| COUNT_NOT_STAR | Invalid COUNT syntax | Critical | No | Templates 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_EXAMINED | Excessive scanned rows | Normal | No | Templates scanning more than 50,000 rows on average. Use more specific filter conditions to reduce the scan range. |
| LARGE_ROWS_SENT | Excessive returned rows | Normal | No | Templates returning more than 5,000 rows on average. Modify the template to limit the result set. |
| NO_ADVICE | No suggestion | Normal | No | No optimization suggestion is available. |
| PERIOD_SQL | Periodic | Normal | No | Templates 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:
| ID | Name | Severity | Description |
|---|---|---|---|
| USER_IGNORE | No need to optimize | Normal | Removes the template from the optimization list starting the next day. |
| DAS_IMPORTANT | High-priority SQL | Normal | Marks the template as high priority. |
| DAS_NOT_IMPORTANT | Low-priority SQL | Normal | Marks the template as low priority. |
| DAS_IN_PLAN | Optimize later | Normal | Marks 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
| Operation | Description |
|---|---|
| CreateQueryOptimizeTag | Adds one or more tags to an SQL template. |
| GetQueryOptimizeExecErrorStats | Queries SQL templates that fail to execute. |
| GetQueryOptimizeExecErrorSample | Queries failed SQL statements in an SQL template. |
| GetQueryOptimizeSolution | Queries optimization suggestions for an SQL template. |
| GetQueryOptimizeRuleList | Queries the list of tags added to slow queries on a database instance. |
| GetQueryOptimizeDataTrend | Queries trend data for query governance results. |
| GetQueryOptimizeDataTop | Queries best-performing and worst-performing instances based on query governance data. |
| GetQueryOptimizeDataStats | Queries SQL template details based on query governance data. |
| GetQueryOptimizeTag | Queries the tags of an SQL template. |
| GetQueryOptimizeShareUrl | Queries the share URL for query governance data. |