index | estimated_storage_size_in_mb
--------------------------------------------+------------------------------
CREATE INDEX ON "School"."Students"("age") | 3
(1 row)
此报告包含单个建议:在 School 架构的 Students 表中的 age 列上添加单列索引。如需应用此建议,请完全按照报告中的表示来输入 DDL 查询:
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-25。"],[[["\u003cp\u003eAlloyDB for PostgreSQL features an index advisor that periodically analyzes database queries to suggest new indexes for improved performance.\u003c/p\u003e\n"],["\u003cp\u003eThe index advisor's recommendations can be viewed via the \u003ccode\u003egoogle_db_advisor_recommended_indexes\u003c/code\u003e and \u003ccode\u003egoogle_db_advisor_workload_report\u003c/code\u003e table views, which include details such as storage estimates and affected queries.\u003c/p\u003e\n"],["\u003cp\u003eUsers can manually request an immediate index analysis by running the \u003ccode\u003eSELECT * FROM google_db_advisor_recommend_indexes();\u003c/code\u003e SQL function.\u003c/p\u003e\n"],["\u003cp\u003eRecommended indexes can be applied by directly executing the \u003ccode\u003eCREATE INDEX\u003c/code\u003e DDL statements provided in the \u003ccode\u003egoogle_db_advisor_recommended_indexes\u003c/code\u003e view.\u003c/p\u003e\n"],["\u003cp\u003eThe index advisor tracks and logs all executed queries, which can be reset using the \u003ccode\u003eSELECT google_db_advisor_reset();\u003c/code\u003e SQL function, and its behavior can be configured with various database flags.\u003c/p\u003e\n"]]],[],null,["# Use the index advisor\n\nAlloyDB for PostgreSQL offers an *index advisor* that tracks the queries your\ndatabase regularly handles. Periodically, it analyzes these queries to\nrecommend new indexes that can increase the queries' performance.\n\nYou can view and query its recommendations as a table, or request an\non-demand analysis and report at any time.\n\nView the index advisor's recommendations\n----------------------------------------\n\nAlloyDB automatically runs the index advisor's analysis\nperiodically. You can\nread its results through two table views located in each of your\ndatabases:\n\n- `google_db_advisor_recommended_indexes` lists any recommended new\n indexes for its database. It also includes estimates of the\n storage required for each index, and the number of queries that each\n index can affect.\n\n- `google_db_advisor_workload_report` lists each query for\n which the advisor recommends one or more new indexes. Each row\n summarizes the recommendations for the relevant query.\n\nFor example, to see the results of the most recent index-recommendation\nanalysis, formatted as a table, run this query: \n\n SELECT * FROM google_db_advisor_recommended_indexes;\n\nIf the index advisor's most recent analysis finds no recommendations,\nthen this query returns a table with no rows.\n\nBecause all of these reports exist as ordinary database views, you can\nwrite queries that filter or present information in any way you\nwish. For example, to see a report that pairs recommended indexes with\ntheir full associated query, join the\n`google_db_advisor_workload_report` and\n[`google_db_advisor_workload_statements`](#view-logs) views on their\nrespective `query_id` columns: \n\n SELECT DISTINCT recommended_indexes, query\n FROM google_db_advisor_workload_report r, google_db_advisor_workload_statements s\n WHERE r.query_id = s.query_id;\n\nManually request an index analysis\n----------------------------------\n\nRather than wait for the index advisor's next scheduled analysis, you\ncan request that AlloyDB run an analysis immediately and\ndisplay its report. To do this, run this SQL function: \n\n SELECT * FROM google_db_advisor_recommend_indexes();\n\nAfter the analysis finishes, AlloyDB\ndisplays a table-formatted report with the description and estimated\nstorage needs of any recommended indexes. If the analysis finds no new\nindexes to recommend, then the view contains no rows.\n\nNote that [the PostgreSQL user role](/alloydb/docs/database-users/about)\nthat runs this command can affect the recommendations displayed. If this\nquery is run by `postgres` or another user with the `alloydbsuperuser`\nrole, then AlloyDB displays all of the index advisor's\ncurrent recommendations. Otherwise, AlloyDB limits its\ndisplay to index recommendations based on queries issued by the current\ndatabase user.\n\nApply the index advisor's recommendations\n-----------------------------------------\n\nThe `index` column of the `google_db_advisor_recommended_indexes` view\ncontains, in each row, a complete PostgreSQL `CREATE INDEX` DDL\nstatement for generating the index recommended in that row.\n\nTo apply that row's recommendation, run that DDL statement, exactly as\npresented. This includes copying it onto your clipboard and pasting it\ninto a `psql` prompt.\n\nFor example, consider this output from manually running an analysis,\nusing the query described in the previous section: \n\n index | estimated_storage_size_in_mb\n --------------------------------------------+------------------------------\n CREATE INDEX ON \"School\".\"Students\"(\"age\") | 3\n (1 row)\n\nThis report contains a single recommendation: adding a new single-column\nindex on the `age` column in the `School` schema's `Students`\ntable. To apply this advice, enter a DDL query exactly as\nrepresented within the report: \n\n CREATE INDEX ON \"School\".\"Students\"(\"age\");\n\nView the index advisor's tracked queries\n----------------------------------------\n\nThe `google_db_advisor_workload_statements` view contains a list of all\nthe queries that the index advisor has tracked, as well as\nimportant metadata for each one, such as the following metrics:\n\n- The number of times the instance executed this query\n- The total time the instance spends processing these queries\n- The ID of the database user running these queries\n\nClear the index advisor's tracked queries\n-----------------------------------------\n\nYou can reset the index advisor's behavior on an instance by\nclearing its tracked queries. To do this, run this SQL function: \n\n SELECT google_db_advisor_reset();\n\nAlloyDB immediately empties the index advisor's\ncollection of tracked queries.\n\nConfigure the index advisor\n---------------------------\n\nWhile the index advisor is designed to work for most use cases with its\ndefault settings, you can fine-tune its behavior by setting various\ndatabase flags. To learn more, see the [Index advisor\nflags](/alloydb/docs/reference/index-advisor-flags) reference page."]]