This page describes the Cloud SQL for MySQL index advisor and how you can view and apply its index recommendations.
Cloud SQL for MySQL offers a fully managed index advisor that tracks the queries your database handles regularly. Periodically, the index advisor analyzes these queries to recommend new indexes that can improve query performance. The index advisor lets you detect and fix performance issues with systems and queries.
How does the index advisor work?The index advisor helps you improve query processing by doing the following:
The index advisor stores and displays the
CREATE INDEX
command containing the database name, table name, and column names. The tracked queries are all normalized queries with all literals removed.
Index recommendations are encrypted at rest.
In Cloud SQL for MySQL, you can use database flags to configure and tune the index advisor. For more information, see
Index advisor flags.
LimitationsCloud SQL for MySQL index advisor has the following limitations:
CREATE INDEX
recommendations only.To obtain index advisor recommendations, you must use Cloud SQL Enterprise Plus edition and enable query insights for Cloud SQL Enterprise Plus edition for your Cloud SQL instance.
Required roles and permissionsTo get the permissions that you need to obtain index advisor recommendations, ask your administrator to grant you the Cloud SQL Viewer (roles/cloudsql.viewer
) IAM role on the project that hosts the Cloud SQL instance. For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the permissions required to obtain index advisor recommendations. To see the exact permissions that are required, expand the Required permissions section:
Required permissionsThe following permissions are required to obtain index advisor recommendations:
databaseinsights.recommendations.query
databaseinsights.resourceRecommendations.query
You might also be able to get these permissions with custom roles or other predefined roles.
Enable index advisor recommendationsWhen you enable query insights for Cloud SQL Enterprise Plus edition, you enable index advisor recommendations automatically.
Disable index advisor recommendationsYou can't disable index advisor recommendations without disabling query insights for Cloud SQL Enterprise Plus edition.
To disable index advisor recommendations and query insights for Cloud SQL Enterprise Plus edition, see Disable query insights for Cloud SQL Enterprise Plus edition.
View index advisor recommendationsCloud SQL automatically runs the index advisor analysis periodically. To view index advisor recommendations, use the Query insights dashboard. You can also view and query the index advisor recommendations as a table or request an on-demand analysis and report at any time.
View and filter recommendations in the Query insights dashboardIn the Google Cloud console, go to the Cloud SQL Instances page.
CREATE INDEX
recommendations, add a filter for Recommendation: Create Indexes.To view index recommendations for a specific query, follow these steps:
In the Google Cloud console, go to the Cloud SQL Instances page.
You can read its results through the following table located in the mysql
database:
mysql.cloudsql_db_advisor_recommended_indexes
: lists any recommended new indexes for each database. It also includes estimates of the storage required for each index, and the number of queries that each index can affect.For example, to see the results of the most recent index-recommendation analysis, formatted as a table, run this query:
SELECT * FROM mysql.cloudsql_db_advisor_recommended_indexes;
Create recommended indexes
You can create recommended indexes from the Query insights dashboard or from a database table view.
Create a recommended index using the Query insights dashboardTo create a recommended index using the Query insights dashboard, do the following:
In the Google Cloud console, go to the Cloud SQL Instances page.
CREATE INDEX
commands are copied to your clipboard.To create the recommended indexes, run the commands that were copied to your clipboard, for example:
CREATE INDEX ON "public"."demo_order" ("customer_id");
The index
column of the mysql.cloudsql_db_advisor_recommended_indexes
table contains, in each row, a complete MySQL CREATE INDEX
DDL statement for generating the index recommended in that row.
To apply that row's recommendation, run that DDL statement, exactly as presented.
For example, consider this output from manually running an analysis, using the query described in the previous section:
index | estimated_storage_size_in_mb
--------------------------------------------+------------------------------
CREATE INDEX ON "School"."Students"("age") | 3
(1 row)
This report contains a single recommendation: adding a single-column index on the age
column in the School
schema's Students
table. To apply this advice, enter a DDL query as represented within the report:
CREATE INDEX ON "School"."Students"("age");
View impacted queries
In the Google Cloud console, go to the Cloud SQL Instances page.
While the index advisor is designed to work for most use cases with its default settings, you can fine-tune its behavior by setting various database flags.
By default, index advisor runs once every 24 hours. You can modify the autoschedule time using the cloudsql_index_advisor_auto_advisor_schedule
flag, or run an ad hoc analysis on a specific date/time using the cloudsql_index_advisor_run_at_timestamp
flag. For more information, see Index advisor flags.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4