All Products
Search
Document Center

Database Autonomy Service:Query governance

Last Updated:Mar 28, 2026

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

TermDescription
Optimizable SQLSQL templates that cause slow queries and need to be optimized.
SQL templates that do not need to be optimizedSQL templates to which DAS automatically adds the Ignored tag, or to which you manually add the Optimization Not Required tag.
IgnoredSQL 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

  1. Log on to the DAS console.

  2. In the left-side navigation pane, click Instance Monitoring.

  3. Find the database instance you want to manage, and click the instance ID.

  4. In the left-side navigation pane, choose Request Analysis > Slow Logs > Query Governance.

  5. 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.
      FilterSeparatorOperator
      Database nameComma (,)OR
      SQL keywordSpaceAND
      UsernameComma (,)OR
      Rule tagSelect multipleOR

      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

IDNameDescription
NEW_SQLNew slow SQLSQL templates that caused slow queries within the past seven days.
INDEX_ADVISORIndex suggestionsQueries on unindexed tables. Create indexes to speed up these queries.
WITHOUT_PREDICATENo predicatesSQL templates with no WHERE conditions. Check whether full table scanning is intentional; if not, rewrite the templates.

Other optimization candidates

IDNameSeverityDescription
DEEP_PAGINGDeep pagingCriticalTemplates using LIMIT for deep paging. Rewrite using JOIN instead of LIMIT.
NULL_COMPARENull match errorCriticalTemplates 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_STARInvalid COUNT syntaxCriticalTemplates using COUNT(column) or COUNT(constant). Use COUNT(*), which is the SQL92 standard and correctly counts rows including NULL values.
FUZZY_LIKELIKE queryNormalTemplates using the LIKE operator for fuzzy matching. Indexes cannot be used for these queries.
HAS_EXPRExpressions containedNormalTemplates with calculation expressions on indexed columns. Indexes cannot be applied to the affected columns.
LARGE_IN_LISTLarge list queryNormalTemplates with more than 200 elements in an IN list. Often auto-generated by application code; indexes cannot be used on the affected columns.
SELECT_STARFull-column queryNormalTemplates in which one or more fields are specified in SELECT clauses, but no conditions are specified, which wastes resources by retrieving unnecessary data.
COMPLEX_JOINComplex JOIN queryNormalTemplates 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_DBCross-database queryNormalTemplates querying data across different databases. After migrating databases or tables to another instance, cross-database queries may fail.
SUBQUERYSubqueries includedNormalTemplates containing subqueries. Rewrite using JOIN for better performance.
LARGE_ROWS_EXAMINEDExcessive scanned rowsNormalTemplates scanning more than 50,000 rows on average. Use more specific filter conditions to reduce the scan range.
LARGE_ROWS_SENTExcessive returned rowsNormalTemplates returning more than 5,000 rows on average. Reduce the number of returned rows by refining the query.
PERIOD_SQLPeriodicNormalTemplates executed at a fixed time each day.
NO_ADVICENo suggestionNormalNo optimization suggestions available.

Auto-ignored by DAS

IDNameDescription
DAS_IGNOREIgnoredSQL 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.

IDNameEffect
USER_IGNORENo Need to OptimizeExcludes the template from the optimization list starting the next day.
DAS_IMPORTANTHigh-priority SQLMarks the template as high priority.
DAS_NOT_IMPORTANTLow-priority SQLMarks the template as low priority.
DAS_IN_PLANOptimize LaterMarks 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.