All Products
Search
Document Center

PolarDB:Slow SQL query

更新時間:Mar 11, 2024

PolarDB for MySQL provides the slow SQL analysis feature. This feature allows you to view slow log trends and statistics. You can also obtain the diagnostic results and suggestions on how to fix slow SQL queries.

Procedure

  1. Log on to the PolarDB console.

  2. In the left-side navigation pane, click Clusters.

  3. In the top navigation bar, select the region in which the cluster that you want to manage is deployed.

  4. Find the cluster and click its ID.

  5. In the left-side navigation pane, choose Diagnostics and Optimization > Slow SQL.

  6. On the Slow Log Analysis tab, specify a time range and view the trends, statistics, and details of the slow query logs within the specified time range.

    Note

    When 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 Log Trend 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.

    • In the Nodes section, you can view the number of slow queries on each node.

    • You can click Export Slow Log to download slow query logs to your computer.

    • On the Slow Log Statistics tab, you can perform the following operations:

      • Find the SQL template that you want to manage and click Sample in the Actions column. In the Slow Log Sample dialog box, view the slow query log sample of the SQL template.

      • Find the SQL template that you want to manage and click Actions in the Optimize column. In the SQL Diagnostic Optimization dialog box, view the SQL diagnostics results.

        If you accept the SQL optimization suggestions, click Copy in the upper-right corner and paste the optimized SQL statement to the database client or Data Management (DMS) for execution. If you do not accept the SQL optimization suggestions, click Cancel.

        Note

        DAS performs SQL diagnostics based on the complexity of SQL statements, the amount of data in the table, and the database workload. Suggestions may be returned in more than 20 seconds after the SQL diagnostics is performed. After the diagnostics is complete, the SQL diagnostics engine provides diagnostics results, optimization suggestions, and expected optimization benefits. You can determine whether to accept the suggestions based on the diagnostics results.

        You can also click Database Expert Service to purchase the expert service. Database Expert Service provides value-added professional database services, such as emergency assistance, health diagnostics, performance optimization, security assurance, and data migration.

      • 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.

      • 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.

        Note
        • The IMCI button is displayed in the Actions column if no IMCI nodes are purchased for the database instance, 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.Max Scanned Rows

        • 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 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.

Related API operations

Operation

Description

DescribeSlowLogRecords

Queries the details of slow logs for a PolarDB for MySQL cluster.

DescribeDBClusterAuditLogCollector

Queries whether SQL data collector is enabled for a PolarDB for MySQL cluster. The features of SQL data collector include audit logs and SQL Explorer.

ModifyDBClusterAuditLogCollector

Enables or disables SQL data collector for a PolarDB for MySQL cluster. The features of the SQL data collector include audit logs and SQL Explorer.