Slow SQL queries can degrade application performance and are often difficult to diagnose manually. Database Autonomy Service (DAS) automatically identifies slow SQL queries in your ApsaraDB RDS for MySQL instance, generates index optimization suggestions, and creates indexes without causing table locks — reducing the need for manual intervention.
Enabling automatic SQL optimization on instances that have both normal and slow SQL queries may cause overall instance performance to degrade. To limit optimization to abnormal queries only, enable the SQL Explorer and Audit feature first. See Use the SQL Explorer and Audit feature.
Prerequisites
Before you begin, make sure your RDS instance runs one of the following MySQL versions and editions:
-
MySQL 8.0 on RDS High-availability Edition, RDS Enterprise Edition, or RDS Cluster Edition, RDS Enterprise Edition,
-
MySQL 5.7 on RDS High-availability Edition, RDS Enterprise Edition, or RDS Cluster Edition, RDS Enterprise Edition,
-
MySQL 5.6 on RDS High-availability Edition
-
MySQL 5.5 on RDS High-availability Edition
The automatic SQL optimization feature does not support SQL queries that involve tables using X-Engine.
How it works
DAS uses Online DDL statements supported by the native MySQL kernel to create indexes. This avoids the table locks that regular index creation can cause. For details, see SQL optimization technology.
DAS runs in two modes:
| Mode | What DAS does |
|---|---|
| SQL Diagnostics Only | Runs daily SQL diagnostics and generates index optimization suggestions. Does not create indexes. |
| SQL Diagnostics and Automatic Index Creation | Runs daily SQL diagnostics, generates index optimization suggestions, and creates indexes based on those suggestions within your instance's maintenance window. |
Enable automatic SQL optimization
-
Go to the Instances page. In the top navigation bar, select the region where your RDS instance resides. Find your instance and click its ID.
-
In the left-side navigation pane, choose Autonomy Services > Diagnostics. On the page that appears, click the Autonomy Center tab, then click Autonomy Service Settings.
-
On the Autonomous Function Settings tab, enable the autonomy service. On the Optimization and Throttling tab, select Automatic Index Creation and Deletion and choose a mode:
-
SQL Diagnostics Only: DAS diagnoses SQL daily and provides index optimization suggestions. No indexes are created.
-
SQL Diagnostics and Automatic Index Creation: DAS diagnoses SQL daily, provides index optimization suggestions, and creates indexes automatically within your maintenance window.
-
-
Click OK.
-
(Optional) In the Alert Configuration section, configure an alert template to receive notifications about automatic SQL optimization tasks. The system recommends an alert template and adds alert rules for the required autonomy events. Follow the prompts to configure it: If you already have an alert template configured for this instance, add the required autonomy event alert rules to that existing template. If you haven't configured one yet, see Configure alert templates and Configure alert rules.
-
In the Select Alert Contact Group step, select an alert contact group. For more information, see Manage alert contacts.
-
Click Add Contact to add an alert contact.
-
Click Create Contact Group to create an alert contact group.
-
To update or remove an existing contact, find it in the list and click Edit or Remove in the Actions column.
-
-
Confirm the settings in the Associate with Resources step.
-
Click Submit Configuration and confirm in the dialog box.
-
View optimization results
On the Autonomy Center tab, view optimization events within a specified time range.
Find the event you want to review and click Details. On the Root Cause Analysis and Suggestions tab of the Slow SQL Statements Diagnostics (Diagnostics and Optimization) event, you can view:
-
Problematic SQL Statements
-
SQL Statement Optimization
-
Index Recommendation
-
Statement Optimization
What's next
To manually optimize a specific SQL statement, see SQL optimization.
API reference
| Operation | Description |
|---|---|
| UpdateAutoSqlOptimizeStatus | Enables, modifies, or disables automatic SQL optimization for multiple database instances at a time. |
| GetSqlOptimizeAdvice | Queries SQL optimization suggestions generated by SQL diagnostics. |
| GetInstanceSqlOptimizeStatistic | Queries statistics on automatic SQL optimization events within a period of time, including total event count and maximum improvement. |