This document describes how you can use AI assistance in Cloud SQL to troubleshoot slow queries in Cloud SQL. You can use the AI assistance capabilities of Cloud SQL and Gemini Cloud Assist to investigate, analyze, obtain recommendations, and finally implement those recommendations to optimize your queries in Cloud SQL.
Before you begin
To troubleshoot slow queries with AI assistance, do the following:
- Review limitations with AI-assisted troubleshooting.
- Enable AI-assisted troubleshooting. This step includes enabling Gemini Cloud Assist.
Required roles and permissions
For the roles and permissions required to troubleshoot slow queries with AI assistance, see Observe and troubleshoot with AI.
Use AI assistance
To use AI assistance with troubleshooting your slow queries, go to the Query insights dashboard for your Cloud SQL instance in Google Cloud console.
Top queries table
You can start troubleshooting slow queries with AI assistance in the Top queries table section of the Query insights dashboard.
Cloud SQL can help you identify which queries are performing slower than average during a specific detection time period. After you select a time range in the Query insights dashboard, Cloud SQL checks whether any queries are performing slower than average by using a detection time period of 24 hours before the end of your selected time range.
When you adjust the time range filter of the Database load chart, or any other filter such as database or user, Cloud SQL refreshes the Top queries table and reruns anomaly detection based on the new list of queries and an updated detection time period.
When Cloud SQL detects an anomaly, Cloud SQL performs baseline performance analysis for your query.
Every listed query in the table has either an Investigate icon or Warning warning_spark icon displayed next to the query's Avg execution time (ms) value.
If a query is running slower than expected, then a Warning warning_spark icon is displayed. When you click either icon, Gemini Cloud Assist is used to help analyze the query execution and offers observations about what might have caused any issue. Based on these observations, Gemini Cloud Assist generates a hypothesis that can help you address the issue.
To troubleshoot slow queries in the Top queries table in the Query insights dashboard, do the following:
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- In the SQL navigation menu, click Query insights.
- In the Executed queries chart, use the Time range filter to select either 1 hour, 6 hours, 1 day, 7 days, 30 days or a custom range.
- In the Top queries table, under the Queries tab, review the list of queries for your database.
- If a Warning warning_spark icon appears next to the query's Avg execution time (ms) value for a query, then Cloud SQL has detected an anomaly in your query performance. Cloud SQL checks for anomalies within the 24-hour time period that occurs before the end of your selected time range.
- Click the Warning warning_spark icon.
- In the Query is slower than usual dialog, click New Investigation
to start troubleshooting with AI assistance from Gemini Cloud Assist.
After about two minutes, the Investigation details pane opens with the
following sections:
- Issue. A description of the issue being investigated, including the investigation’s start and stop time.
- Observations. A list of observations about the issue. For example, these can include lock contention details, such as a longer than expected lock wait ratio for the query.
- Hypotheses. A list of AI-recommended actions to take to help address the slow running query.
If you want to see all investigations associated with the query, in the Query is slower than usual dialog, click View all investigations. The Gemini Cloud Assist page opens where you can view all currently running and previously completed investigations. You can filter the page by project or label, for example, to find the specific investigation you need.
Alternatively, to see all previous investigations, click the Notifications icon, then select a notification associated with any investigation to open the Gemini Cloud Assist page.
- Alternatively, if you want to investigate the latency of any query, complete the following steps:
- Identify the specific query you want to investigate.
- In the Actions column, click the Actions icon associated with that query.
- Select Investigate latency in the menu to run a Gemini Cloud Assist investigation.
Query details
You can also troubleshoot a slow query with AI assistance from the Query details page.
-
In the Google Cloud console, go to the Cloud SQL Instances page.
- To open the Overview page of an instance, click the instance name.
- Click Query insights to open the Query insights dashboard.
- In the Query insights dashboard, click the query in the Top queries that you want to view. The Query details page appears.
- If Cloud SQL detects an anomaly for the query, then one or more of the following indicators appears in the Query details page:
- A message on the details screen that says
This query is slower than usualand an Investigate option. A message in the Query latency chart that says
Query slower than usual. If this message appears, then click Investigate button to start troubleshooting with AI assistance from Gemini Cloud Assist.After about two minutes, the Investigation details pane opens with the following sections:
- Issue. A description of the issue being investigated, including the investigation’s start and stop time.
- Observations. A list of observations about the issue. For example, these can include lock contention details, such as a longer than expected lock wait ratio for the query.
- Hypotheses. A list of AI-recommended actions to take to help address the slow running query.
- Optional: Use the Time range filter to select either 1 hour, 6 hours, 1 day, 7 days, 30 days or a custom range. When you adjust the Time range filter of the Query details page , or any other filter such as Database or User, Cloud SQL reruns anomaly detection.
- If Cloud SQL doesn't detect an anomaly for the query, then you can still run an analysis on the query by clicking the Investigate button in the Query latency card.
Analyze query latency
Using AI assistance, you can analyze and troubleshoot the details of your query latency.
Analysis time period
The analysis time period consists of the 24 hours that occur before the end of the time range that you select in the Database load chart of the Query insights dashboard or the Query details page. Cloud SQL uses this time period to compare baseline metrics with the metrics retrieved during the time period of the anomaly.
On the Query details page, if Cloud SQL has detected an anomaly with the query, then after you select the query from the Query insights dashboard, Cloud SQL performs a baseline performance analysis for the query using the last 24 hours from the end of the anomaly. If Cloud SQL hasn't detected an anomaly with the query and runs anomaly detection on the query again, then Cloud SQL uses 48 hours before the end of the selected time range as the performance baseline for the analysis time period.
Detected anomaly period
The detected anomaly period represents a time period when Cloud SQL finds an anomalous change in query performance. Cloud SQL uses the baseline performance measured for the query during the analysis time period.
If Cloud SQL detects multiple anomalies for a query within a selected time period, then Cloud SQL uses the last detected anomaly.
If you want to continue troubleshooting or get more assistance with query performance, then you can also open Gemini Cloud Assist. For more information, see Observe and troubleshoot with AI assistance.