Use index advisor Stay organized with collections Save and categorize content based on your preferences.
This page describes the Cloud SQL for MySQL index advisor and how you can viewand apply its index recommendations.
Cloud SQL for MySQL offers a fully managed index advisor that tracks thequeries your database handles regularly. Periodically, the index advisoranalyzes these queries to recommend new indexes that can improve queryperformance. The index advisor lets you detect and fix performanceissues with systems and queries.
How does the index advisor work?
The index advisor helps you improve query processing bydoing the following:
- Recommend a set of indexes with SQL commands to create indexes.
- Provide data to help you evaluate recommended indexes, for example,estimated storage size and impact of indexes on a query.
CREATE INDEX command containing thedatabase name, table name, and column names. The tracked queriesare 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 theindex advisor. For more information, seeIndex advisor flags.Limitations
Cloud SQL for MySQL index advisor has the following limitations:
- The index advisor provides
CREATE INDEXrecommendations only. - The index advisor doesn't support instances with the following configurations:
- Cloud SQL Enterprise edition instances
- Instances that use shared-core machine types
Before you begin
To obtain index advisor recommendations,you must use Cloud SQL Enterprise Plus edition and enablequery insights for Cloud SQL Enterprise Plus editionfor your Cloud SQL instance.
Required roles and permissions
To get the permissions that you need to obtain index advisor recommendations, ask your administrator to grant you theCloud SQL Viewer (roles/cloudsql.viewer) IAM role on the project that hosts the Cloud SQL instance. For more information about granting roles, seeManage 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 theRequired permissions section:
Required permissions
The following permissions are required to obtain index advisor recommendations:
databaseinsights.recommendations.querydatabaseinsights.resourceRecommendations.query
You might also be able to get these permissions withcustom roles or otherpredefined roles.
Enable index advisor recommendations
When youenable query insights for Cloud SQL Enterprise Plus edition,you enable index advisor recommendations automatically.
Disable index advisor recommendations
You 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, seeDisable query insights for Cloud SQL Enterprise Plus edition.
View index advisor recommendations
Cloud SQL automatically runs the index advisor analysisperiodically. To view index advisor recommendations, use the Query insights dashboard.You can also view and query the index advisor recommendations as a table or requestan on-demand analysis and report at any time.
View and filter recommendations in the Query insights dashboard
In the Google Cloud console, go to theCloud SQL Instances page.
- To open theOverview page of an instance, click the instance name.
- ClickQuery insights.
- The index advisor recommendations are displayed intheRecommendation column of theTop queries and tagssection.
- Optional: To view only the queries with
CREATE INDEXrecommendations, add afilter forRecommendation: Create Indexes.
View recommendations for a query
To view index recommendations for a specific query, follow thesesteps:
In the Google Cloud console, go to theCloud SQL Instances page.
- To open theOverview page of an instance, click the instance name.
- ClickQuery insights.
- In theTop queries and tags section, clickQueries.
- To get recommendation details for a query, do one of the following:
- Click a query to learn more about the recommendations for the selectedquery, including the following information:
- Performance impact (high, medium, and low): Theestimated query speed after all recommended indexes are created.
- Recommendations: Create index recommendations.
- Tables impacted: The number of tables that will beimpacted when indexes are created.
- Additional estimated storage needed: The estimatedstorage size needed to create all the recommended indexes.
- Number of impacted queries: The total number ofqueries in the workload impacted by the index recommendations. Anindex can benefit multiple queries.
- ClickCreate Indexes for a specific query to learn detailedrecommendations about creating indexes to improve query performance.
- Click a query to learn more about the recommendations for the selectedquery, including the following information:
View recommendations as a database table view
You can read its results through the following table located in themysqldatabase:
mysql.cloudsql_db_advisor_recommended_indexes: lists any recommended newindexes for each database. It also includes estimates of thestorage required for each index, and the number of queries that eachindex can affect.
For example, to see the results of the most recent index-recommendationanalysis, formatted as a table, run this query:
SELECT*FROMmysql.cloudsql_db_advisor_recommended_indexes;Create recommended indexes
You can create recommended indexes from the Query insights dashboard orfrom a database table view.
Create a recommended index using the Query insights dashboard
To create a recommended index using the Query insights dashboard, do thefollowing:
In the Google Cloud console, go to theCloud SQL Instances page.
- To open theOverview page of an instance, click the instance name.
- ClickQuery insights.
- In theTop dimensions by database load table, clickQueries.
- ClickCreate Indexes for a specific query.
- ClickCopy all index commands. The
CREATE INDEXcommands are copiedto your clipboard. - Connect to the primary instance on the command line.
To create the recommended indexes, run the commands that were copied toyour clipboard, for example:
CREATEINDEXON"public"."demo_order"("customer_id");
Create a recommended index using a database table view
Theindex column of themysql.cloudsql_db_advisor_recommended_indexes tablecontains, in each row, a complete MySQLCREATE INDEX DDLstatement for generating the index recommended in that row.
To apply that row's recommendation, run that DDL statement, exactly aspresented.
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-columnindex on theage column in theSchool schema'sStudentstable. To apply this advice, enter a DDL query asrepresented within the report:
CREATEINDEXON"School"."Students"("age");View impacted queries
In the Google Cloud console, go to theCloud SQL Instances page.
- To open theOverview page of an instance, click the instance name.
- ClickQuery insights.
- In theTop dimensions by database load table, clickQueries.
- ClickCreate indexes for a specific query.
- ClickShow impacted queries.
- Click a query to learn details about the impacted query.
Configure the index advisor
While the index advisor is designed to work for most use cases with itsdefault settings, you can fine-tune its behavior by setting variousdatabase flags.
By default, index advisor runs once every 24 hours. You can modify theautoschedule time using thecloudsql_index_advisor_auto_advisor_scheduleflag, or run an ad hoc analysis on a specificdate/time using thecloudsql_index_advisor_run_at_timestamp flag.For more information, seeIndex advisor flags.
What's next
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.