Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Halaman ini menjelaskan penasihat indeks Spanner dan cara Anda dapat melihat serta menerapkan rekomendasi indeksnya. Penasihat indeks tersedia untuk database dialek GoogleSQL dan database dialek PostgreSQL.
Penasihat indeks Spanner menganalisis kueri Anda untuk merekomendasikan indeks baru atau yang diubah yang dapat meningkatkan performa kueri Anda. Anda dapat melihat rekomendasi
penasihat indeks di konsol Google Cloud menggunakan salah satu pendekatan berikut:
Untuk melihat rekomendasi CREATE INDEX dan ALTER INDEX, Anda dapat menggunakan konsol Google Cloud .
Untuk mengetahui informasi selengkapnya tentang indeks Spanner, lihat
Indeks sekunder.
Batasan
Penasihat indeks Spanner memiliki batasan berikut:
Hanya memberikan rekomendasi CREATE INDEX dan ALTER INDEX. Tidak menyediakan rekomendasi DROP INDEX untuk indeks yang ada.
Rekomendasi indeks hanya ditampilkan jika memberikan manfaat performa
yang signifikan.
Jika Anda adalah pengguna kontrol akses terperinci atau jika Anda tidak
memiliki akses DDL, Anda tidak dapat menjalankan pernyataan DDL rekomendasi indeks. Anda
dapat menyalin dan menyimpan rekomendasi.
Menggunakan rencana eksekusi kueri
Untuk melihat dan menerapkan rekomendasi penasihat indeks dari rencana eksekusi kueri,
ikuti langkah-langkah berikut.
Lihat rekomendasi
Untuk melihat rencana eksekusi kueri, jalankan kueri di konsol Google Cloud :
Buka halaman Instance Spanner di
konsolGoogle Cloud .
Pilih instance yang berisi database yang ingin Anda buat kueri.
Pilih nama database yang ingin Anda buat kueri.
Di menu navigasi, klik Spanner Studio.
Buka tab editor SQL baru.
Di panel editor, masukkan kueri SQL Anda.
Klik Run.
Setelah kueri selesai berjalan, untuk melihat rencana eksekusi kueri, klik tab Explanation.
Panel informasi menampilkan informasi mendetail tentang kueri. Jika
Spanner menentukan bahwa indeks baru atau yang diubah dapat meningkatkan
performa kueri Anda, kartu rekomendasi indeks akan ditampilkan.
Untuk melihat pernyataan DDL rekomendasi indeks, di kartu Rekomendasi indeks, klik Lihat detail untuk melihat indeks.
Menerapkan rekomendasi
Rekomendasi indeks Spanner memberikan pernyataan DDL CREATE INDEX
dan ALTER INDEX lengkap untuk indeks yang direkomendasikan.
Untuk menerapkan rekomendasi penasihat indeks, salin dan jalankan pernyataan DDL
penasihat indeks ke editor Spanner Studio persis seperti yang ditampilkan.
Di panel Rekomendasi indeks, centang kotak di samping pernyataan DDL
yang ingin Anda salin.
Klik Salin ke tab baru.
Di tab editor Spanner Studio yang baru, jalankan pernyataan DDL yang disalin.
Menggunakan dasbor Query Insights
Untuk melihat dan menerapkan rekomendasi penasihat indeks dari dasbor Insight kueri, ikuti langkah-langkah berikut.
Lihat rekomendasi
Buka halaman Instance Spanner di
konsolGoogle Cloud .
Pilih nama instance yang berisi database yang ingin Anda buat kueri.
Pilih nama database yang ingin Anda buat kueri.
Di menu navigasi, klik Insight kueri.
Lihat tabel Kueri dan tag TopN.
Tabel menampilkan kolom Recommendation. Jika Spanner
menentukan bahwa indeks baru atau yang diubah dapat meningkatkan performa kueri Anda,
rekomendasi indeks akan ditampilkan. Untuk melihat tampilannya di konsol Google Cloud , lihat Mengidentifikasi kueri atau tag permintaan yang berpotensi bermasalah.
Untuk melihat pernyataan DDL rekomendasi indeks, klik Rekomendasi indeks.
Menerapkan rekomendasi
Rekomendasi indeks Spanner memberikan pernyataan DDL CREATE INDEX
dan ALTER INDEX lengkap untuk indeks yang direkomendasikan.
Untuk menerapkan rekomendasi penasihat indeks, salin dan jalankan pernyataan DDL
penasihat indeks ke editor Spanner Studio persis seperti yang ditampilkan.
Di panel Index recommendation, pilih pernyataan DDL yang ingin
Anda salin.
Spanner membuat rekomendasi untuk kueri TopN setiap 12
jam untuk kueri TopN yang dijalankan dalam 12 jam sebelumnya. Panel
Rekomendasi indeks menampilkan catatan tentang berapa lama yang lalu indeks terakhir kali
dimuat ulang.
Klik Salin ke Spanner Studio.
Google Cloud konsol akan menampilkan editor Spanner Studio.
Jika Anda adalah pengguna kontrol akses terperinci, Anda tidak akan melihat tombol Salin ke
Spanner Studio, dan Anda tidak dapat menjalankan pernyataan DDL.
Di editor Spanner Studio, jalankan pernyataan DDL yang disalin.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-05 UTC."],[],[],null,["# Use the Spanner index advisor\n\nThis page describes the Spanner index advisor and how you can view and\napply its index recommendations. The index advisor is available for\nGoogleSQL-dialect databases and PostgreSQL-dialect databases.\n\nThe Spanner index advisor analyzes your queries to recommend new\nor altered indexes that can improve your query performance. You can view the\nindex advisor's recommendations in the Google Cloud console using either of the\nfollowing approaches:\n\n- Run a query and view its [query execution plan](/spanner/docs/query-execution-plans)\n- Use the Spanner [Query insights dashboard](/spanner/docs/using-query-insights)\n\nTo view the `CREATE INDEX` and `ALTER INDEX` recommendations, you can\nuse the Google Cloud console.\n\nFor more information about Spanner indexes, see\n[Secondary indexes](/spanner/docs/secondary-indexes).\n\nLimitations\n-----------\n\nSpanner index advisor has the following limitations:\n\n- Only provides `CREATE INDEX` and `ALTER INDEX` recommendations. Doesn't\n provide `DROP INDEX` recommendations for existing indexes.\n\n- An index recommendation is only shown if it provides a noticeable performance\n benefit.\n\n- If you are a [fine-grained access control](/spanner/docs/fgac-about) user or if you don't\n have DDL access, you can't execute index recommendation DDL statements. You\n can copy and save the recommendation.\n\nUse the query execution plan\n----------------------------\n\nTo view and apply index advisor recommendations from a query's execution plan,\nfollow these steps.\n\n### View recommendations\n\nTo view the query execution plan, run a query in the Google Cloud console:\n\n1. Go to the Spanner **Instances** page in\n Google Cloud console.\n\n [Go to Instances](https://console.cloud.google.com/spanner/instances)\n2. Select the instance that contains the database that you want to query.\n\n3. Select the name of the database you want to query.\n\n4. In the navigation menu, click **Spanner Studio**.\n\n5. Open a new SQL editor tab.\n\n6. In the editor pane, enter your SQL query.\n\n7. Click **Run**.\n\n8. After the query has finished running, to see the query execution plan, click\n the **Explanation** tab.\n\n The information panel shows detailed information about the query. If\n Spanner determines that a new or altered index can improve\n your query performance, then an index recommendations card is displayed.\n9. To view the index recommendation DDL statement, in the **Index recommendation**\n card, click **View details** to view the index.\n\n### Apply recommendations\n\nThe Spanner index recommendation provides complete `CREATE INDEX`\nand `ALTER INDEX` DDL statements for recommended indexes.\n\nTo apply the index advisor's recommendation, copy and run the index advisor's\nDDL statement into the Spanner Studio editor exactly as presented.\n\n1. In the **Index recommendation** pane, select the checkbox next to the DDL\n statements that you want to copy.\n\n2. Click **Copy to new tab**.\n\n3. In the new Spanner Studio editor tab, run the copied DDL statement.\n\nUse the Query insights dashboard\n--------------------------------\n\nTo view and apply index advisor recommendations from the Query insights\ndashboard, follow these steps.\n\n### View recommendations\n\n1. Go to the Spanner **Instances** page in\n Google Cloud console.\n\n [Go to Instances](https://console.cloud.google.com/spanner/instances)\n2. Select the name of the instance containing the database you want to query.\n\n3. Select the name of the database you want to query.\n\n4. In the navigation menu, click **Query insights**.\n\n5. View the **TopN queries and tags** table.\n\n The table shows a **Recommendation** column. If Spanner\n determines that a new or altered index can improve your query performance,\n then an index recommendation is displayed. To view what this looks\n like in the Google Cloud console, see\n [Identify a potentially problematic query or request tag](/spanner/docs/using-query-insights#filter-db-load).\n6. To view the index recommendation DDL statement, click **Index recommendation**.\n\n### Apply recommendations\n\nThe Spanner index recommendation provides complete `CREATE INDEX`\nand `ALTER INDEX` DDL statements for recommended indexes.\n\nTo apply the index advisor's recommendation, copy and run the index advisor's\nDDL statement into the Spanner Studio editor exactly as presented.\n\n1. In the **Index recommendation** pane, select the DDL statements you want to\n copy.\n\n Spanner generates recommendations for TopN queries every 12\n hours for the TopN queries executed in the preceding 12 hours. The\n **Index recommendation** pane displays a record of how long ago it was last\n refreshed.\n\n2. Click **Copy to Spanner Studio** .\n Google Cloud console displays the **Spanner Studio** editor.\n\n If you are a fine-grained access control user, you don't see the **Copy to\n Spanner Studio** button, and you can't run the DDL statement.\n3. In the Spanner Studio editor, run the copied DDL statement.\n\nWhat's next\n-----------\n\n- Learn more about Spanner [secondary indexes](/spanner/docs/secondary-indexes).\n\n- Learn more [SQL best practices](/spanner/docs/sql-best-practices).\n\n- Learn how to [Troubleshoot performance regressions](/spanner/docs/troubleshooting-performance-regressions)."]]