Query Governance helps you identify and prioritize slow queries that need optimization. Provided by Database Autonomy Service (DAS), it automatically classifies slow queries on your RDS for MySQL instance, assigns severity-based tags daily at 01:00, and provides index suggestions and SQL rewrite advice to guide your optimization work.
Prerequisites
Before you begin, ensure that your instance meets the following requirements:
-
Your RDS instance runs one of the following MySQL versions and RDS editions:
MySQL version Supported RDS editions MySQL 8.0 High-availability Edition, RDS Enterprise Edition, Cluster Edition MySQL 5.7 High-availability Edition, RDS Enterprise Edition, Cluster Edition MySQL 5.6 High-availability Edition MySQL 5.5 High-availability Edition -
The instance is deployed in one of the following regions: the Chinese mainland, China (Hong Kong), or Singapore.
Support for China (Hong Kong) and Singapore was added on April 1, 2023.
Limitations
-
Query Governance uses T+1 analysis — it processes data from the previous day. Tag changes take effect the following day. For example, if you add the Optimization Not Required tag to an SQL template today, the template is excluded from the optimizable list starting tomorrow.
-
Tags added by the system cannot be changed or removed.
-
DAS analyzes only the top 200 most frequently executed slow queries per instance, so each instance can have at most 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 tagged as Ignored or Optimization Not Required. |
| Ignored | SQL templates to which DAS automatically adds the Optimization Not Required tag. Includes templates starting with SHOW, CREATE, XA, COMMIT, ROLLBACK, SELECT SLEEP, or EXPLAIN. |
View query governance results
-
Go to the Instances page. In the top navigation bar, select the region where your RDS instance resides, then click the instance ID.
-
In the left-side navigation pane, choose Autonomy Services > Slow Query Logs.
-
Click the Query Governance tab.
The Query Governance page has five sections: Overview, Trend chart, Top Rankings, SQL to Be Optimized, and Failed SQL. Use the filters at the top of the page to scope results by time range, region, database engine, or instance ID.
Overview
Displays the query governance results after SQL templates are categorized and tags are added to the SQL templates.
To view Failed SQL Executions in the Overview, you must purchase DAS Enterprise Edition.
Trend chart
Shows how query governance results change over a selected time range.
Top Rankings
Displays two charts:
-
Worst-performing Instances — lists instances in descending order of slow query count, helping you identify which instance has the most slow queries.
-
Best-performing Instances — lists instances in ascending order of change in slow query count. A negative value means fewer slow queries compared to the previous day; a positive value means more. This helps you identify where SQL optimization is having the greatest impact.
Focus on the instance with the most slow queries and the instance with the greatest improvement.
SQL to Be Optimized
Lists the SQL templates that need optimization. Filter the list using any combination of these conditions (all four conditions are evaluated with AND):
| Filter | Separator for multiple values | Logic |
|---|---|---|
| Database name | Comma (,) |
OR |
| SQL keyword | Space | AND |
| Rule tag | Multiple selectable | OR |
| Username of database account | Comma (,) |
OR |
For each SQL template in the list, the Actions column provides:
-
Suggestions — view optimization recommendations, including index suggestions and SQL rewrite advice.
-
Add Tag — add a user tag to the template. Select multiple templates to tag them in bulk.
-
Sample — view the 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. You can specify database names and SQL keywords to filter SQL statements. The filter conditions are evaluated by using the AND operator.
-
Separate multiple database names with commas (
,). The database names are evaluated by using the OR operator. -
Separate multiple SQL keywords with spaces. The SQL keywords are evaluated by using the AND operator.
To access Failed SQL, you must purchase DAS Enterprise Edition.
Click Sample in the Actions column to view the details of a failed SQL statement.
Best practices
Use tags to prioritize optimization work
DAS assigns system tags to each slow SQL template automatically. Tags marked Critical need immediate attention; tags marked Normal can be addressed in order of business impact.
Start with the tags that require immediate attention (NEW_SQL, WITHOUT_PREDICATE, INDEX_ADVISOR), then work through the remaining Critical tags before moving to Normal severity.
System tags (read-only)
| Tag ID | Tag name | Severity | Immediate attention required | Description |
|---|---|---|---|---|
| NEW_SQL | New slow SQL | Critical | Yes | Templates that caused slow queries within the past 7 days. |
| WITHOUT_PREDICATE | No predicates | Critical | Yes | Templates without predicates. Check whether full table scanning is required. If not, rewrite the template. |
| INDEX_ADVISOR | Index suggestions | Normal | Yes | Queries on unindexed tables. Create and use indexes to speed up these queries. |
| DEEP_PAGING | Deep paging | Critical | No | Templates using LIMIT for deep paging. Rewrite to use JOIN instead. |
| NULL_COMPARE | Null match error | Critical | No | Templates using ISNULL() to check for NULL values. You cannot use the ISNULL() function to find NULL values because NULL is returned if one of the values is NULL. |
| COUNT_NOT_STAR | Invalid COUNT syntax | Critical | No | Templates using COUNT(column name) or COUNT(constant). Use COUNT(*), which is the SQL92 standard and counts rows including NULL values. |
| 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 used on the involved columns. |
| LARGE_IN_LIST | Large list query | Normal | No | Templates with more than 200 elements in an IN clause. These are often auto-generated by programs; indexes cannot be used on the involved columns. |
| SELECT_STAR | Full-column query | Normal | No | Templates selecting fields with no filter conditions, causing unnecessary data to be retrieved. |
| COMPLEX_JOIN | Complex JOIN query | Normal | No | Templates joining more than 3 tables. Make sure the joined fields have the same data type and are indexed. |
| CROSS_DB | Cross-database query | Normal | No | Templates querying data across multiple databases. Cross-database queries may fail after database or table migration. |
| SUBQUERY | Subqueries included | Normal | No | Templates containing subqueries. Rewrite using JOIN for better performance. |
| 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 reduce returned rows. |
| PERIOD_SQL | Periodic | Normal | No | Templates executed at the same time each day. |
| DAS_IGNORE | Ignored | Normal | No | Templates automatically excluded from optimization (starts with SHOW, CREATE, XA, COMMIT, ROLLBACK, SELECT SLEEP, or EXPLAIN). |
| NO_ADVICE | No suggestion | Normal | No | No optimization suggestions available. |
User tags
Add these tags manually to track the optimization status of SQL templates.
| Tag ID | Tag name | Description |
|---|---|---|
| USER_IGNORE | No need to optimize | Removes the template from the optimizable list starting the next day. |
| DAS_IMPORTANT | High-priority SQL | Marks the template as high priority. |
| DAS_NOT_IMPORTANT | Low-priority SQL | Marks the template as low priority. |
| DAS_IN_PLAN | Optimize later | Marks the template for future optimization. |
Add the Optimization Not Required tag to SQL templates that do not need optimization before DAS runs its daily analysis. This reduces the count of SQL templates listed under SQL to Be Optimized.
Export data
-
In the SQL to Be Optimized section, apply filters to scope the SQL templates you want — for example, filter by database name or rule tag.
-
Click Export in the upper-right corner of the SQL Details section.
Exported files are available for download for 3 days.
To distribute optimization work across your team, create separate export tasks filtered by database or rule tag, then assign each file to the team member responsible for those SQL templates. To export a subset, select specific SQL templates before clicking Export.
Share data
Share filtered SQL templates with the owners responsible for optimization. Two methods are available:
-
Share all filtered results — apply your filters, then click Share (next to Export). The system generates a URL that shows all SQL templates matching your filters.
-
Share selected results — select specific SQL templates, then click Batch Sharing. The system generates a URL that shows only the selected templates.
Anyone with DAS permissions can open the URL to view the shared SQL templates.