All Products
Search
Document Center

ApsaraDB RDS:Query governance

Last Updated:Sep 19, 2025

Database Autonomy Service (DAS) provides a query governance feature for ApsaraDB RDS for PostgreSQL. This feature uses offline data analytics to analyze slow SQL statements from the previous day at 01:00 daily. DAS automatically adds tags to these statements to help you classify and prioritize them for governance. The feature also provides optimization suggestions and lets you export data.

Prerequisites

  • The ApsaraDB RDS for PostgreSQL instance is a High-availability Edition instance.

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

    Note

    Starting from April 1, 2023, the query governance feature is supported for database instances that reside in the China (Hong Kong) and Singapore regions.

Limits

  • The query governance feature is implemented by analyzing offline data the day after the transaction (T+1). For example, if you add the Optimization Not Required tag to an SQL template, the SQL template is removed from the SQL templates that need to be optimized on the next day.

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

  • For each database instance, DAS counts and analyzes only the top 200 slow queries that are most frequently executed. This indicates that the maximum number of slow SQL templates of a database instance is 200.

Terms

Term

Description

Optimizable SQL

The SQL templates that cause slow queries and need to be optimized.

SQL templates that do not need to be optimized

The SQL templates that cause slow queries and to which DAS automatically adds the Ignored tag or to which you add the Optimization Not Required tag.

Ignored

The SQL templates that cause slow queries and to which DAS automatically adds the Optimization Not Required tag. These SQL templates include the SQL templates that start with the SHOW, CREATE, XA, COMMIT, ROLLBACK, SELECT SLEEP, or EXPLAIN statement.

Procedure

  1. Go to the Instances page. In the top navigation bar, select the region in which the RDS instance resides. Then, find the RDS instance and click the ID of the instance.

  2. In the navigation pane on the left, choose Autonomy Services > Slow Query Logs > Query Governance.

  3. On the Query Governance page, view the query governance results.

    • Query governance overview: Displays the results after the system classifies and tags the SQL statements.

      Note

      Statistics for Failed SQL Executions are collected only for instances with DAS Enterprise Edition enabled.

    • Query governance trend: Displays the trend of query governance results over the selected time range.

    • Top Rankings: Displays the Best-performing Instances and Worst-performing Instances charts.

      • Worst-performing Instances: Shows the number of slow SQL statement executions on the database instance.

      • Best-performing Instances: Shows the change in the number of slow SQL statement executions. A negative number indicates a decrease and successful optimization, while a positive number indicates an increase.

      DAS recommends that you focus on the best-performing and worst-performing charts for Optimizable SQL.

    • SQL to Be Optimized: You can set filter conditions to find the SQL statements that require governance.

      Note

      You can filter statements by DB name, SQL keyword, rule tag, and database username. These conditions are joined by a logical AND.

      • To specify multiple DB names, separate them with commas (,). This creates a logical OR.

      • To specify multiple SQL keywords, separate them with spaces. This creates a logical AND.

      • To specify multiple database usernames, separate them with commas (,). This creates a logical OR.

      • You can select multiple rule tags. This creates a logical OR.

      • Click Suggestions in the Actions column for the target SQL statement to view detailed governance suggestions.

      • Click Add Tag in the Actions column for the target SQL statement to manually add a tag. For more information about tags, see Manual tags.

        You can also select multiple SQL statements and tag them in a batch.

      • Click Sample in the Actions column for the target SQL statement to view the details of the slow query log sample.

      • Click Trend in the Actions column for the target SQL statement to view the analysis details for the slow SQL statement. For more information about slow query log analysis, see Slow SQL.

      You can export and share the data for the SQL statements that need to be optimized. For more information, see Best practices.

    • Failed SQL: You can set filter conditions to find the failed SQL statements that you want to view.

      Note
      • Statistics for Failed SQL are collected only for instances with DAS Enterprise Edition enabled.

      • You can filter statements by DB name and SQL keyword. These conditions are joined by a logical AND.

        • To specify multiple DB names, separate them with commas (,). This creates a logical OR.

        • To specify multiple SQL keywords, separate them with spaces. This creates a logical AND.

      Click Sample in the Actions column for the target SQL statement to view the sample details.

Best practices

  • Use tags to identify SQL statements that require optimization.

    The core logic of query governance is to divide All Slow SQL Statements into two categories: Optimization Not Required and Optimizable SQL. You can use SQL tags to quickly filter statements and prioritize them for optimization.

    ID

    Name

    Severity level

    Immediate attention required

    Description

    NEW_SQL

    New Slow SQL

    Critical

    ✔️

    SQL templates that caused slow queries within the previous seven days.

    DAS_IGNORE

    Ignored

    Normal

    SQL templates to which DAS automatically adds the Optimization Not Required tag. These SQL templates include the SQL templates that start with the SHOW, CREATE, XA, COMMIT, ROLLBACK, SELECT SLEEP, or EXPLAIN statement.

    FUZZY_LIKE

    LIKE Query

    Normal

    SQL templates in which the LIKE operator is used to implement fuzzy matching. Indexes cannot be used in queries that contain the LIKE operator.

    HAS_EXPR

    Expressions Contained

    Normal

    SQL templates that contain calculation expressions. Indexes cannot be used on the involved columns.

    LARGE_IN_LIST

    Large List Query

    Normal

    SQL templates in which more than 200 elements are specified for the IN operator. Such SQL templates may be automatically generated by programs. Indexes cannot be used on the involved columns.

    SELECT_STAR

    Full-column Query

    Normal

    SQL templates in which one or more fields are specified in SELECT clauses, but no conditions are specified. If you do not specify conditions, resources are wasted for querying unnecessary data. This reduces query performance.

    INDEX_ADVISOR

    Index Suggestions

    Normal

    ✔️

    SQL templates that are used to query data from tables that are not indexed. We recommend that you create and use indexes to accelerate SQL queries.

    COMPLEX_JOIN

    Complex JOIN Query

    Normal

    SQL templates in which the JOIN operator is used to join more than three tables. You cannot use the JOIN operator to join more than three tables. The data type of the specified fields in the tables that you want to join must be the same. Before you join multiple tables, make sure that you create indexes for the fields that you want to query in the tables.

    CROSS_DB

    Cross-database Query

    Normal

    SQL templates that are used to query data in different databases. After databases or tables are migrated from the original database instance to another database instance, cross-database queries may fail.

    SUBQUERY

    Subqueries Included

    Normal

    SQL templates that contain SQL statements for subqueries. We recommend that you rewrite the SQL templates and use the JOIN operator to make queries more efficient.

    DEEP_PAGING

    Deep Paging

    Critical

    SQL templates in which the LIMIT operator is used to implement the deep paging method. We recommend that you rewrite the SQL templates and use the JOIN operator instead of the LIMIT operator.

    WITHOUT_PREDICATE

    No Predicates

    Critical

    ✔️

    SQL templates that do not contain predicates. Check whether your business requires full table scanning. If your business does not require full table scanning, rewrite the SQL templates.

    NULL_COMPARE

    Null Match Error

    Critical

    SQL templates in which the ISNULL() function is used 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

    SQL templates that contain invalid COUNT syntax. Use COUNT(*) to query the number of data records. Do not use the COUNT (Column name) or COUNT (Constant) syntax. COUNT(*) is the standard syntax that is defined in SQL92 to query the number of rows. The COUNT(*) syntax counts the number of data records that include NULL values and can be executed on all types of databases. The COUNT (Column name) syntax does not count NULL values.

    LARGE_ROWS_EXAMINED

    Excessive Scanned Rows

    Normal

    SQL templates that are used to scan more than 50,000 rows on average. A larger number of rows consume a larger amount of database resources. This causes the SQL queries to execute slowly and affects other SQL queries.

    Note

    We recommend that you use more specific filter conditions in SQL statements.

    LARGE_ROWS_SENT

    Excessive Returned Rows

    Normal

    SQL templates that are used in queries for which more than 5,000 rows of data on average are returned. We recommend that you modify the SQL templates to reduce the number of returned rows.

    NO_ADVICE

    No suggestion

    Normal

    No suggestions are provided.

    PERIOD_SQL

    Periodic

    Normal

    SQL templates that are executed at a specific point in time on a daily basis.

    DAS recommends that you focus on Optimizable SQL. Use the tags in the following table to manually tag SQL statements as Optimization Not Required to continuously reduce the number of Optimizable SQL statements.

    ID

    Name

    Severity level

    Description

    USER_IGNORE

    No Need to Optimize

    Normal

    After you add this tag to an SQL template, the SQL template is not counted in the SQL templates that need to be optimized on the next day.

    DAS_IMPORTANT

    High-priority SQL

    Normal

    Add this tag to SQL templates that are of high priority.

    DAS_NOT_IMPORTANT

    Low-priority SQL

    Normal

    Add this tag to SQL templates that are of low priority.

    DAS_IN_PLAN

    Optimize Later

    Normal

    Add this tag to SQL templates that are to be optimized later.

  • Export data.

    • Click Export in the upper-right corner of the SQL Details section to export the data of the filtered SQL templates.

      Note

      The exported data is available for download for three days.

    • You can specify different conditions to filter SQL templates. For example, you can filter SQL templates based on databases or rule tags, create download tasks, and then assign different owners to optimize SQL templates based on databases or rule tags.

    • You can also select multiple SQL templates and export the data of the selected SQL templates.

  • Share data.

    You can filter SQL templates and share the filtered SQL templates with the owners of the corresponding SQL templates. You can use one of the following methods to share data:

    • Select SQL templates and click Batch Sharing in the lower part of the section. The system generates a URL. On the page to which the URL directs, the information about the selected SQL templates is displayed. If you are granted the permissions on DAS, you can visit the page to view the information about the selected SQL templates.

    • Specify conditions to filter SQL templates and click Share to the right of Export. The system generates a URL. On the page to which the URL directs, the information about the filtered SQL templates is displayed. If you are granted the permissions on DAS, you can visit the page to view the information about all filtered SQL templates.