From e45f664ca4f04edeabf8a67020b87590a3778e69 Mon Sep 17 00:00:00 2001 From: Matthew Jacobson Date: Wed, 24 Jan 2024 16:18:14 -0500 Subject: [PATCH] Alerting: Replace index role_id, action, scope with action, scope, role_id on permission table (#80336) * Alerting: Add action, scope, role_id to permission table The existing role_id, action, scope index has the wrong ordering to be most effectively used in dashboard/folder permission requests. On a large tests set, the slow database calls were on the order of ~30-40ms, so when performed individually they don't have that large of a latency impact. However, when done in bulk in the migration this adds up to some very slow requests. After the index is added these same database calls are reduced to ~4-5ms * Change index to action, scope, role_id * Make new index unique and drop [role_id, action, scope] index --- .../sqlstore/migrations/accesscontrol/migrations.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/services/sqlstore/migrations/accesscontrol/migrations.go b/pkg/services/sqlstore/migrations/accesscontrol/migrations.go index a7819085f71..da3c021dee0 100644 --- a/pkg/services/sqlstore/migrations/accesscontrol/migrations.go +++ b/pkg/services/sqlstore/migrations/accesscontrol/migrations.go @@ -186,4 +186,14 @@ func AddMigration(mg *migrator.Migrator) { mg.AddMigration("add permission identifier index", migrator.NewAddIndexMigration(permissionV1, &migrator.Index{ Cols: []string{"identifier"}, })) + + mg.AddMigration("add permission action scope role_id index", migrator.NewAddIndexMigration(permissionV1, &migrator.Index{ + Type: migrator.UniqueIndex, + Cols: []string{"action", "scope", "role_id"}, + })) + + mg.AddMigration("remove permission role_id action scope index", migrator.NewDropIndexMigration(permissionV1, &migrator.Index{ + Type: migrator.UniqueIndex, + Cols: []string{"role_id", "action", "scope"}, + })) }