Slow queries accumulate quietly — and without a systematic way to classify and prioritize them, teams spend hours investigating the wrong SQL first. Query governance analyzes the previous day's slow queries every day at 01:00:00, classifies each SQL template by problem type, and assigns severity tags. Use the results to filter by database, rule, or owner, then export or share assignments to coordinate optimization across your team.
Supported regions and availability
Database type: PolarDB for MySQL clusters only
Regions: Chinese mainland, China (Hong Kong), Singapore
Support for the China (Hong Kong) and Singapore regions was added on April 1, 2023.
Limits
Query governance runs on T+1 offline data. Changes you make — such as tagging an SQL template — take effect the following day.
System-added tags cannot be changed or removed.
DAS analyzes only the top 200 most frequently executed slow queries per instance. 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 to which DAS automatically adds the Ignored tag, or to which you manually add the Optimization Not Required tag. |
| Ignored | SQL templates that DAS auto-tags as not requiring optimization (adds the Optimization Not Required tag). Includes templates starting 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, click Instance Monitoring.
Find the database instance you want to manage, and click the instance ID.
In the left-side navigation pane, choose Request Analysis > Slow Logs > Query Governance.
On the Query Governance tab, review the following sections:
Overview: A snapshot of how SQL templates are categorized and tagged after the latest analysis.
Note: To view Failed SQL Executions, purchase DAS Enterprise Edition.
Trend chart: The change in query governance results over a selected time range.
Top Rankings: The Worst-performing Instances and Best-performing Instances charts. Pay immediate attention to the instance with the most slow queries and the instance where optimization has had the greatest impact.
Worst-performing Instances: The number of slow queries executed on each instance.
Best-performing Instances: The day-over-day change in slow query count. A negative value means fewer slow queries than the previous day, indicating that SQL optimization is taking effect. A positive value indicates that a larger number of slow queries are executed compared with the previous day.
SQL to Be Optimized: Filter and manage SQL templates that need optimization.
Note: You can filter by database name, SQL keyword, rule tag, and database account username. All four conditions are combined with AND. To specify multiple values within a single condition, see the table below.
Filter Separator Operator Database name Comma (,) OR SQL keyword Space AND Username Comma (,) OR Rule tag Select multiple OR For each SQL template in the list:
Click Suggestions to view optimization advice.
Click Add Tag to manually tag the template. Select multiple templates to tag them in bulk.
Click Sample to view the slow query logs for the template.
Click Trend to view slow query log analysis details. For more information, see Slow query logs.
Failed SQL: Filter and view SQL statements that failed to execute.
Note: Viewing Failed SQL requires DAS Enterprise Edition. Filter by database name (comma-separated, evaluated by OR) and SQL keyword (space-separated, evaluated by AND). Click Sample to view the details of a specific statement.
Best practices
Use tags to prioritize optimization work
DAS classifies slow SQL templates by problem type and assigns tags. The tags below are grouped by priority — start with those that require immediate attention.
Tags that require immediate attention
| ID | Name | Description |
|---|---|---|
| NEW_SQL | New slow SQL | SQL templates that caused slow queries within the past seven days. |
| INDEX_ADVISOR | Index suggestions | Queries on unindexed tables. Create indexes to speed up these queries. |
| WITHOUT_PREDICATE | No predicates | SQL templates with no WHERE conditions. Check whether full table scanning is intentional; if not, rewrite the templates. |
Other optimization candidates
| ID | Name | Severity | Description |
|---|---|---|---|
| DEEP_PAGING | Deep paging | Critical | Templates using LIMIT for deep paging. Rewrite using JOIN instead of LIMIT. |
| NULL_COMPARE | Null match error | Critical | 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 | Templates using COUNT(column) or COUNT(constant). Use COUNT(*), which is the SQL92 standard and correctly counts rows including NULL values. |
| FUZZY_LIKE | LIKE query | Normal | Templates using the LIKE operator for fuzzy matching. Indexes cannot be used for these queries. |
| HAS_EXPR | Expressions contained | Normal | Templates with calculation expressions on indexed columns. Indexes cannot be applied to the affected columns. |
| LARGE_IN_LIST | Large list query | Normal | Templates with more than 200 elements in an IN list. Often auto-generated by application code; indexes cannot be used on the affected columns. |
| SELECT_STAR | Full-column query | Normal | Templates in which one or more fields are specified in SELECT clauses, but no conditions are specified, which wastes resources by retrieving unnecessary data. |
| COMPLEX_JOIN | Complex JOIN query | Normal | Templates joining more than three tables. You cannot use the JOIN operator to join more than three tables. Verify that joined fields share the same data type, and create indexes on the fields being queried before joining multiple tables. |
| CROSS_DB | Cross-database query | Normal | Templates querying data across different databases. After migrating databases or tables to another instance, cross-database queries may fail. |
| SUBQUERY | Subqueries included | Normal | Templates containing subqueries. Rewrite using JOIN for better performance. |
| LARGE_ROWS_EXAMINED | Excessive scanned rows | Normal | 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 | Templates returning more than 5,000 rows on average. Reduce the number of returned rows by refining the query. |
| PERIOD_SQL | Periodic | Normal | Templates executed at a fixed time each day. |
| NO_ADVICE | No suggestion | Normal | No optimization suggestions available. |
Auto-ignored by DAS
| ID | Name | Description |
|---|---|---|
| DAS_IGNORE | Ignored | SQL templates starting with SHOW, CREATE, XA, COMMIT, ROLLBACK, SELECT SLEEP, or EXPLAIN. DAS automatically marks these as not requiring optimization. |
Add manual tags to manage your backlog
Before DAS runs its daily analysis, add one of the following tags to remove an SQL template from the optimization list or mark it for follow-up.
| ID | Name | Effect |
|---|---|---|
| USER_IGNORE | No Need to Optimize | Excludes the template from the optimization 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. |
Export data for team collaboration
To export SQL template data from the SQL Details section:
Click Export in the upper-right corner of the SQL Details section to export all filtered templates. The download link is available for three days.
Filter by database or rule tag, create separate export tasks, and assign them to different owners for targeted optimization.
Select specific templates and click Export to export only the selected items.
Share filtered results
To share filtered SQL templates with template owners:
Select templates and click Batch Sharing. DAS generates a URL that displays the selected templates. Anyone with DAS permissions can open the URL to view the results.
Apply filter conditions and click Share (next to Export). DAS generates a URL that displays all templates matching your current filters. Anyone with DAS permissions can open the URL to view the results.