Updated on 2024-10-24 GMT+08:00

Why Is My SQL Query So Slow?

  1. You can view the slow SQL logs for slow SQL queries and view their performance characteristics (if any) to locate the cause.

    To learn how to view RDS for MySQL logs, see Viewing and Downloading Slow Query Logs.

    To learn how to view RDS for PostgreSQL logs, see Viewing and Downloading Error Logs.

    For RDS for SQL Server, you can query dynamic management views (DMVs) to locate the cause of slow queries. For details on DMVs, visit the Microsoft official website.

  2. View the CPU usage metric of your DB instance.

    For details, see Viewing Performance Metrics.

  3. Create read replicas to offload read pressure on primary DB instances.
  4. When multiple associated tables are queried, indexes must be created for the associated fields.
  5. Do not use the SELECT statement to scan all tables. You can specify fields or add the WHERE condition.