Slow SQL queries significantly decrease the database stability. When issues such as high workloads and performance jitters occur on databases, database administrators (DBAs) or developers first check whether slow query logs are generated. Database Autonomy Service (DAS) provides the log analysis feature for slow queries. DAS collects statistics on and analyzes SQL statements whose execution duration exceeds the specified threshold value and provides solutions. You can troubleshoot database performance issues with ease. This enhances system reliability and stability.
Prerequisites
The database engine is PolarDB for MySQL.
PolarDB for MySQL Enterprise Edition Single Node Edition is not supported.
Background information
Slow query logs are generated by the database kernel. Relevant parameters and thresholds vary based on the database engine. For more information, see the corresponding official documentation.
Procedure
Log on to the DAS console.
In the left-side navigation pane, choose Intelligent O&M Center > Instance Monitoring.
On the page that appears, find the database instance that you want to manage and click the instance ID. The instance details page appears.
In the left-side navigation pane, choose Request Analysis > Slow Logs.
On the Slow Log Analysis tab, specify a time range and view the Slow Query Log Trends, Event Distribution, Slow Query Log Statistics, and Slow Query Log Details within the specified time range.
NoteWhen you specify the time range, the end time must be later than the start time, and the interval between the start time and the end time cannot exceed 24 hours. You can query slow query logs within the previous month.
In the Slow Query Log Trends section, you can click a point in time in the trend chart and view the statistics and details of the slow query logs at the point in time.
NoteIf the content of an SQL statement is not completely displayed due to length limits of the GUI, you can move the pointer over the SQL statement to view the complete content.
In the Event Distribution section, perform the following operation:
You can query slow query log events within the specified time range. Click an event to view its details.
Select the desired node from the Node ID drop-down list to view the number of slow queries on the node.
Click the
icon to download slow query logs to your computer.
Click
to populate the selected and entered parameters to the OpenAPI console for API debugging.
On the Slow Query Log Statistics tab, perform the following operations:
Configure filter conditions in the upper part of the list. Different database engines have different filter conditions.
Click the SQL ID that corresponds to the SQL template that you want to manage, to view the user distribution, client distribution, and metric trend correlation and detailed list.
Click Optimize in the Actions column corresponding to the SQL template. In the SQL Diagnostic Optimization dialog box, view the SQL diagnosis results.
If you accept the SQL optimization suggestions, click Copy in the upper-right corner and paste the optimized SQL statements to the database client or Data Management (DMS) for execution. If you do not accept the SQL optimization suggestions, click Cancel.
NoteDAS performs SQL diagnostics based on the complexity of SQL statements, the amount of data in the table, and the database load. Suggestions may be returned in more than 20 seconds after the SQL diagnostics is performed. After the diagnostics is complete, the SQL diagnostic engine provides diagnostic results, optimization suggestions, and expected optimization benefits. You can determine whether to accept the suggestions based on the diagnostic results.
Find the SQL template that you want to manage and click Throttling in the Actions column. In the SQL Throttling dialog box, configure the parameters. For more information, see SQL throttling.
For a PolarDB for MySQL cluster, find the SQL template that you want to manage and click IMCI in the Actions column to view the documentation of the In-Memory Column Index (IMCI) feature.
NoteThe IMCI button is displayed in the Actions column if no IMCI nodes are purchased for the PolarDB for MySQL cluster, the maximum execution duration of the SQL template exceeds 20 seconds, and the maximum number of scanned rows of the SQL template exceeds 200,000.
We recommend that you use the IMCI feature to improve query performance when you require complex queries on a large amount of data.
On the Slow Query Log Details tab, find the SQL statement that you want to manage and click Optimize or Throttling in the Actions column. This way, you can also perform SQL diagnostics or SQL throttling.
FAQ
Q: Why is the execution completion time of SQL statements recorded in slow query logs different from the actual execution completion time of the SQL statements?
A: This issue usually occurs when the time zones recorded in the slow query logs are modified by the executed SQL statements. The execution completion time of an SQL statement varies with the time zone recorded in slow query logs at the following levels: session level, database level, and system level. If a time zone is specified for the database, the execution completion time of an SQL statement is recorded based on the time zone of the database. Otherwise, the execution completion time of an SQL statement is recorded based on the time zone of the system. If an SQL statement modifies the time zone at the session level, the time zone recorded in slow query logs may not be properly converted.
References
You can enable the autonomy features of DAS. This way, when slow SQL queries are detected on your database instance, DAS automatically optimizes the slow SQL queries.